summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libudev/libudev-device.c56
-rw-r--r--src/libudev/libudev-private.h4
-rw-r--r--src/test/test-udev.c3
-rw-r--r--src/udev/udevadm-test.c6
4 files changed, 48 insertions, 21 deletions
diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c
index c182f07373..d510b47cd1 100644
--- a/src/libudev/libudev-device.c
+++ b/src/libudev/libudev-device.c
@@ -36,6 +36,8 @@
#include "libudev.h"
#include "libudev-private.h"
+static int udev_device_read_uevent_file(struct udev_device *udev_device);
+static int udev_device_read_db(struct udev_device *udev_device);
static int udev_device_set_devnode(struct udev_device *udev_device, const char *devnode);
static struct udev_list_entry *udev_device_add_property_internal(struct udev_device *udev_device, const char *key, const char *value);
@@ -462,6 +464,16 @@ void udev_device_ensure_usec_initialized(struct udev_device *udev_device, struct
udev_device_set_usec_initialized(udev_device, now(CLOCK_MONOTONIC));
}
+static int udev_device_set_action(struct udev_device *udev_device, const char *action)
+{
+ free(udev_device->action);
+ udev_device->action = strdup(action);
+ if (udev_device->action == NULL)
+ return -ENOMEM;
+ udev_device_add_property_internal(udev_device, "ACTION", udev_device->action);
+ return 0;
+}
+
/*
* parse property string, and if needed, update internal values accordingly
*
@@ -582,7 +594,7 @@ _public_ const char *udev_device_get_property_value(struct udev_device *udev_dev
return udev_list_entry_get_value(list_entry);
}
-int udev_device_read_db(struct udev_device *udev_device)
+static int udev_device_read_db(struct udev_device *udev_device)
{
char filename[UTIL_PATH_SIZE];
char line[UTIL_LINE_SIZE];
@@ -646,7 +658,7 @@ int udev_device_read_db(struct udev_device *udev_device)
return 0;
}
-int udev_device_read_uevent_file(struct udev_device *udev_device)
+static int udev_device_read_uevent_file(struct udev_device *udev_device)
{
char filename[UTIL_PATH_SIZE];
FILE *f;
@@ -1897,16 +1909,6 @@ ssize_t udev_device_get_properties_monitor_buf(struct udev_device *udev_device,
return udev_device->monitor_buf_len;
}
-int udev_device_set_action(struct udev_device *udev_device, const char *action)
-{
- free(udev_device->action);
- udev_device->action = strdup(action);
- if (udev_device->action == NULL)
- return -ENOMEM;
- udev_device_add_property_internal(udev_device, "ACTION", udev_device->action);
- return 0;
-}
-
int udev_device_get_devlink_priority(struct udev_device *udev_device)
{
if (!udev_device->info_loaded)
@@ -2053,6 +2055,36 @@ struct udev_device *udev_device_new_from_nulstr(struct udev *udev, char *nulstr,
return device;
}
+struct udev_device *udev_device_new_from_synthetic_event(struct udev *udev, const char *syspath, const char *action) {
+ struct udev_device *ret;
+ int r;
+
+ if (!action) {
+ errno = EINVAL;
+ return NULL;
+ }
+
+ ret = udev_device_new_from_syspath(udev, syspath);
+ if (!ret)
+ return NULL;
+
+ r = udev_device_read_uevent_file(ret);
+ if (r < 0) {
+ udev_device_unref(ret);
+ errno = -r;
+ return NULL;
+ }
+
+ r = udev_device_set_action(ret, action);
+ if (r < 0) {
+ udev_device_unref(ret);
+ errno = -r;
+ return NULL;
+ }
+
+ return ret;
+}
+
int udev_device_copy_properties(struct udev_device *dst, struct udev_device *src) {
struct udev_list_entry *entry;
diff --git a/src/libudev/libudev-private.h b/src/libudev/libudev-private.h
index 403ae599f6..32c5e19a12 100644
--- a/src/libudev/libudev-private.h
+++ b/src/libudev/libudev-private.h
@@ -38,6 +38,7 @@ int udev_get_rules_path(struct udev *udev, char **path[], usec_t *ts_usec[]);
/* libudev-device.c */
struct udev_device *udev_device_new_from_nulstr(struct udev *udev, char *nulstr, ssize_t buflen);
+struct udev_device *udev_device_new_from_synthetic_event(struct udev *udev, const char *syspath, const char *action);
struct udev_device *udev_device_shallow_clone(struct udev_device *old_device);
struct udev_device *udev_device_clone_with_db(struct udev_device *old_device);
int udev_device_copy_properties(struct udev_device *dst, struct udev_device *src);
@@ -50,9 +51,6 @@ void udev_device_cleanup_devlinks_list(struct udev_device *udev_device);
int udev_device_add_property(struct udev_device *udev_device, const char *key, const char *value);
char **udev_device_get_properties_envp(struct udev_device *udev_device);
ssize_t udev_device_get_properties_monitor_buf(struct udev_device *udev_device, const char **buf);
-int udev_device_read_db(struct udev_device *udev_device);
-int udev_device_read_uevent_file(struct udev_device *udev_device);
-int udev_device_set_action(struct udev_device *udev_device, const char *action);
const char *udev_device_get_devpath_old(struct udev_device *udev_device);
const char *udev_device_get_id_filename(struct udev_device *udev_device);
void udev_device_set_is_initialized(struct udev_device *udev_device);
diff --git a/src/test/test-udev.c b/src/test/test-udev.c
index 4403624c5a..23b7faa939 100644
--- a/src/test/test-udev.c
+++ b/src/test/test-udev.c
@@ -110,13 +110,12 @@ int main(int argc, char *argv[]) {
rules = udev_rules_new(udev, 1);
strscpyl(syspath, sizeof(syspath), "/sys", devpath, NULL);
- dev = udev_device_new_from_syspath(udev, syspath);
+ dev = udev_device_new_from_synthetic_event(udev, syspath, action);
if (dev == NULL) {
log_debug("unknown device '%s'", devpath);
goto out;
}
- udev_device_set_action(dev, action);
event = udev_event_new(dev);
sigfillset(&mask);
diff --git a/src/udev/udevadm-test.c b/src/udev/udevadm-test.c
index 542c56eb1a..fe092cfbd9 100644
--- a/src/udev/udevadm-test.c
+++ b/src/udev/udevadm-test.c
@@ -117,18 +117,16 @@ static int adm_test(struct udev *udev, int argc, char *argv[]) {
strscpy(filename, sizeof(filename), syspath);
util_remove_trailing_chars(filename, '/');
- dev = udev_device_new_from_syspath(udev, filename);
+ dev = udev_device_new_from_synthetic_event(udev, filename, action);
if (dev == NULL) {
fprintf(stderr, "unable to open device '%s'\n", filename);
rc = 4;
goto out;
}
- /* skip reading of db, but read kernel parameters */
+ /* don't read info from the db */
udev_device_set_info_loaded(dev);
- udev_device_read_uevent_file(dev);
- udev_device_set_action(dev, action);
event = udev_event_new(dev);
sigfillset(&mask);