diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 03:50:40 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 03:50:40 +0000 |
commit | fc53809803cd2bc2434e312b19a18fa36776da12 (patch) | |
tree | b4b43bd6538f51965ce32856e9c053d0f90919c8 /src/udev/udev-builtin.c | |
parent | Adding upstream version 255.5. (diff) | |
download | systemd-fc53809803cd2bc2434e312b19a18fa36776da12.tar.xz systemd-fc53809803cd2bc2434e312b19a18fa36776da12.zip |
Adding upstream version 256.upstream/256
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/udev/udev-builtin.c')
-rw-r--r-- | src/udev/udev-builtin.c | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/src/udev/udev-builtin.c b/src/udev/udev-builtin.c index bcc2018..1a1cb37 100644 --- a/src/udev/udev-builtin.c +++ b/src/udev/udev-builtin.c @@ -99,7 +99,7 @@ UdevBuiltinCommand udev_builtin_lookup(const char *command) { return _UDEV_BUILTIN_INVALID; } -int udev_builtin_run(UdevEvent *event, UdevBuiltinCommand cmd, const char *command, bool test) { +int udev_builtin_run(UdevEvent *event, UdevBuiltinCommand cmd, const char *command) { _cleanup_strv_free_ char **argv = NULL; int r; @@ -117,10 +117,10 @@ int udev_builtin_run(UdevEvent *event, UdevBuiltinCommand cmd, const char *comma /* we need '0' here to reset the internal state */ optind = 0; - return builtins[cmd]->cmd(event, strv_length(argv), argv, test); + return builtins[cmd]->cmd(event, strv_length(argv), argv); } -int udev_builtin_add_property(sd_device *dev, bool test, const char *key, const char *val) { +int udev_builtin_add_property(sd_device *dev, EventMode mode, const char *key, const char *val) { int r; assert(dev); @@ -131,13 +131,13 @@ int udev_builtin_add_property(sd_device *dev, bool test, const char *key, const return log_device_debug_errno(dev, r, "Failed to add property '%s%s%s'", key, val ? "=" : "", strempty(val)); - if (test) + if (mode == EVENT_UDEVADM_TEST_BUILTIN) printf("%s=%s\n", key, strempty(val)); return 0; } -int udev_builtin_add_propertyf(sd_device *dev, bool test, const char *key, const char *valf, ...) { +int udev_builtin_add_propertyf(sd_device *dev, EventMode mode, const char *key, const char *valf, ...) { _cleanup_free_ char *val = NULL; va_list ap; int r; @@ -152,5 +152,28 @@ int udev_builtin_add_propertyf(sd_device *dev, bool test, const char *key, const if (r < 0) return log_oom_debug(); - return udev_builtin_add_property(dev, test, key, val); + return udev_builtin_add_property(dev, mode, key, val); +} + +int udev_builtin_import_property(sd_device *dev, sd_device *src, EventMode mode, const char *key) { + const char *val; + int r; + + assert(dev); + assert(key); + + if (!src) + return 0; + + r = sd_device_get_property_value(src, key, &val); + if (r == -ENOENT) + return 0; + if (r < 0) + return log_device_debug_errno(src, r, "Failed to get property \"%s\", ignoring: %m", key); + + r = udev_builtin_add_property(dev, mode, key, val); + if (r < 0) + return r; + + return 1; } |