From: Lennart Poettering Date: Wed, 10 Feb 2021 21:15:01 +0000 (+0100) Subject: sd-device: add sd_device_get_action() + sd_device_get_seqnum() + sd_device_new_from_s... X-Git-Tag: v248-rc1~54^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a11300221482da7ffe7be2d75d508ddd411814f6;p=thirdparty%2Fsystemd.git sd-device: add sd_device_get_action() + sd_device_get_seqnum() + sd_device_new_from_stat_rdev() To make sd-device properly usable for all programs we need to provide an API for the "action" field of an event, it's one of the most relevant ones, and it was so far missing. This also adds sd_device_get_seqnum(), which isn't that interesting, except for generating pretty debug output, which we use it ourselves for. This also makes device_new_from_stat_rdev() public, as it is truly useful, as we can see in our own uses of it, and I think is fairly generic to show up in the public APIs. --- diff --git a/src/core/device.c b/src/core/device.c index db39479c8fc..356c389c55c 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -7,7 +7,6 @@ #include "bus-error.h" #include "dbus-device.h" #include "dbus-unit.h" -#include "device-private.h" #include "device-util.h" #include "device.h" #include "log.h" @@ -916,8 +915,8 @@ static int device_remove_old(Manager *m, sd_device *dev) { } static int device_dispatch_io(sd_device_monitor *monitor, sd_device *dev, void *userdata) { + sd_device_action_t action; Manager *m = userdata; - DeviceAction action; const char *sysfs; int r; @@ -930,22 +929,22 @@ static int device_dispatch_io(sd_device_monitor *monitor, sd_device *dev, void * return 0; } - r = device_get_action(dev, &action); + r = sd_device_get_action(dev, &action); if (r < 0) { log_device_error_errno(dev, r, "Failed to get udev action: %m"); return 0; } - if (!IN_SET(action, DEVICE_ACTION_ADD, DEVICE_ACTION_REMOVE, DEVICE_ACTION_MOVE)) + if (!IN_SET(action, SD_DEVICE_ADD, SD_DEVICE_REMOVE, SD_DEVICE_MOVE)) device_propagate_reload_by_sysfs(m, sysfs); - if (action == DEVICE_ACTION_MOVE) + if (action == SD_DEVICE_MOVE) (void) device_remove_old(m, dev); /* A change event can signal that a device is becoming ready, in particular if the device is using * the SYSTEMD_READY logic in udev so we need to reach the else block of the following if, even for * change events */ - if (action == DEVICE_ACTION_REMOVE) { + if (action == SD_DEVICE_REMOVE) { r = swap_process_device_remove(m, dev); if (r < 0) log_device_warning_errno(dev, r, "Failed to process swap device remove event, ignoring: %m"); @@ -1013,7 +1012,7 @@ static int validate_node(Manager *m, const char *node, sd_device **ret) { } else { _cleanup_(sd_device_unrefp) sd_device *dev = NULL; - r = device_new_from_stat_rdev(&dev, &st); + r = sd_device_new_from_stat_rdev(&dev, &st); if (r == -ENOENT) { *ret = NULL; return 1; /* good! (though missing) */ diff --git a/src/core/swap.c b/src/core/swap.c index 5746940fa87..a81b1928b89 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -10,7 +10,6 @@ #include "alloc-util.h" #include "dbus-swap.h" #include "dbus-unit.h" -#include "device-private.h" #include "device-util.h" #include "device.h" #include "escape.h" @@ -307,7 +306,7 @@ static int swap_load_devnode(Swap *s) { if (stat(s->what, &st) < 0 || !S_ISBLK(st.st_mode)) return 0; - r = device_new_from_stat_rdev(&d, &st); + r = sd_device_new_from_stat_rdev(&d, &st); if (r < 0) { log_unit_full_errno(UNIT(s), r == -ENOENT ? LOG_DEBUG : LOG_WARNING, r, "Failed to allocate device for swap %s: %m", s->what); @@ -510,7 +509,7 @@ static int swap_process_new(Manager *m, const char *device, int prio, bool set_f if (stat(device, &st) < 0 || !S_ISBLK(st.st_mode)) return 0; - r = device_new_from_stat_rdev(&d, &st); + r = sd_device_new_from_stat_rdev(&d, &st); if (r < 0) { log_full_errno(r == -ENOENT ? LOG_DEBUG : LOG_WARNING, r, "Failed to allocate device for swap %s: %m", device); diff --git a/src/home/homed-manager.c b/src/home/homed-manager.c index 1b13002627f..f0c844b0cb0 100644 --- a/src/home/homed-manager.c +++ b/src/home/homed-manager.c @@ -1234,7 +1234,7 @@ static int manager_on_device(sd_device_monitor *monitor, sd_device *d, void *use assert(m); assert(d); - if (device_for_action(d, DEVICE_ACTION_REMOVE)) { + if (device_for_action(d, SD_DEVICE_REMOVE)) { const char *sysfs; Home *h; diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 3de3b4e26f0..823cf0a25f4 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -30,7 +30,6 @@ #include "catalog.h" #include "chattr-util.h" #include "def.h" -#include "device-private.h" #include "dissect-image.h" #include "fd-util.h" #include "fileio.h" @@ -207,7 +206,7 @@ static int add_matches_for_device(sd_journal *j, const char *devpath) { if (stat(devpath, &st) < 0) return log_error_errno(errno, "Couldn't stat file: %m"); - r = device_new_from_stat_rdev(&device, &st); + r = sd_device_new_from_stat_rdev(&device, &st); if (r < 0) return log_error_errno(r, "Failed to get device from devnum %u:%u: %m", major(st.st_rdev), minor(st.st_rdev)); diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym index f9970a2e52d..fbe9803d42c 100644 --- a/src/libsystemd/libsystemd.sym +++ b/src/libsystemd/libsystemd.sym @@ -745,4 +745,8 @@ global: sd_event_source_set_ratelimit; sd_event_source_get_ratelimit; sd_event_source_is_ratelimited; + + sd_device_get_action; + sd_device_get_seqnum; + sd_device_new_from_stat_rdev; } LIBSYSTEMD_247; diff --git a/src/libsystemd/sd-device/device-internal.h b/src/libsystemd/sd-device/device-internal.h index 3321c8e2dc6..c1a81e3b41a 100644 --- a/src/libsystemd/sd-device/device-internal.h +++ b/src/libsystemd/sd-device/device-internal.h @@ -76,7 +76,7 @@ struct sd_device { gid_t devgid; /* only set when device is passed through netlink */ - DeviceAction action; + sd_device_action_t action; uint64_t seqnum; bool parent_set:1; /* no need to try to reload parent */ diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c index c39ac3f3b95..b14f43aae53 100644 --- a/src/libsystemd/sd-device/device-private.c +++ b/src/libsystemd/sd-device/device-private.c @@ -183,20 +183,8 @@ static int device_set_devgid(sd_device *device, const char *gid) { return 0; } -int device_get_action(sd_device *device, DeviceAction *action) { - assert(device); - - if (device->action < 0) - return -ENOENT; - - if (action) - *action = device->action; - - return 0; -} - static int device_set_action(sd_device *device, const char *action) { - DeviceAction a; + sd_device_action_t a; int r; assert(device); @@ -206,7 +194,7 @@ static int device_set_action(sd_device *device, const char *action) { if (a < 0) return a; - r = device_add_property_internal(device, "ACTION", action); + r = device_add_property_internal(device, "ACTION", device_action_to_string(a)); if (r < 0) return r; @@ -215,18 +203,6 @@ static int device_set_action(sd_device *device, const char *action) { return 0; } -int device_get_seqnum(sd_device *device, uint64_t *seqnum) { - assert(device); - - if (device->seqnum == 0) - return -ENOENT; - - if (seqnum) - *seqnum = device->seqnum; - - return 0; -} - static int device_set_seqnum(sd_device *device, const char *str) { uint64_t seqnum; int r; @@ -724,22 +700,6 @@ int device_new_from_synthetic_event(sd_device **new_device, const char *syspath, return 0; } -int device_new_from_stat_rdev(sd_device **ret, const struct stat *st) { - char type; - - assert(ret); - assert(st); - - if (S_ISBLK(st->st_mode)) - type = 'b'; - else if (S_ISCHR(st->st_mode)) - type = 'c'; - else - return -ENOTTY; - - return sd_device_new_from_devnum(ret, type, st->st_rdev); -} - int device_copy_properties(sd_device *device_dst, sd_device *device_src) { const char *property, *value; int r; @@ -1003,19 +963,19 @@ int device_delete_db(sd_device *device) { return 0; } -static const char* const device_action_table[_DEVICE_ACTION_MAX] = { - [DEVICE_ACTION_ADD] = "add", - [DEVICE_ACTION_REMOVE] = "remove", - [DEVICE_ACTION_CHANGE] = "change", - [DEVICE_ACTION_MOVE] = "move", - [DEVICE_ACTION_ONLINE] = "online", - [DEVICE_ACTION_OFFLINE] = "offline", - [DEVICE_ACTION_BIND] = "bind", - [DEVICE_ACTION_UNBIND] = "unbind", +static const char* const device_action_table[_SD_DEVICE_ACTION_MAX] = { + [SD_DEVICE_ADD] = "add", + [SD_DEVICE_REMOVE] = "remove", + [SD_DEVICE_CHANGE] = "change", + [SD_DEVICE_MOVE] = "move", + [SD_DEVICE_ONLINE] = "online", + [SD_DEVICE_OFFLINE] = "offline", + [SD_DEVICE_BIND] = "bind", + [SD_DEVICE_UNBIND] = "unbind", }; -DEFINE_STRING_TABLE_LOOKUP(device_action, DeviceAction); +DEFINE_STRING_TABLE_LOOKUP(device_action, sd_device_action_t); void dump_device_action_table(void) { - DUMP_STRING_TABLE(device_action, DeviceAction, _DEVICE_ACTION_MAX); + DUMP_STRING_TABLE(device_action, sd_device_action_t, _SD_DEVICE_ACTION_MAX); } diff --git a/src/libsystemd/sd-device/device-private.h b/src/libsystemd/sd-device/device-private.h index e8bf2f547e8..ec76f772e5f 100644 --- a/src/libsystemd/sd-device/device-private.h +++ b/src/libsystemd/sd-device/device-private.h @@ -10,22 +10,8 @@ #include "macro.h" -typedef enum DeviceAction { - DEVICE_ACTION_ADD, - DEVICE_ACTION_REMOVE, - DEVICE_ACTION_CHANGE, - DEVICE_ACTION_MOVE, - DEVICE_ACTION_ONLINE, - DEVICE_ACTION_OFFLINE, - DEVICE_ACTION_BIND, - DEVICE_ACTION_UNBIND, - _DEVICE_ACTION_MAX, - _DEVICE_ACTION_INVALID = -EINVAL, -} DeviceAction; - int device_new_from_nulstr(sd_device **ret, uint8_t *nulstr, size_t len); int device_new_from_strv(sd_device **ret, char **strv); -int device_new_from_stat_rdev(sd_device **ret, const struct stat *st); int device_get_id_filename(sd_device *device, const char **ret); @@ -34,8 +20,6 @@ int device_get_watch_handle(sd_device *device, int *handle); int device_get_devnode_mode(sd_device *device, mode_t *mode); int device_get_devnode_uid(sd_device *device, uid_t *uid); int device_get_devnode_gid(sd_device *device, gid_t *gid); -int device_get_action(sd_device *device, DeviceAction *action); -int device_get_seqnum(sd_device *device, uint64_t *seqnum); void device_seal(sd_device *device); void device_set_is_initialized(sd_device *device); @@ -73,6 +57,6 @@ static inline int device_read_db(sd_device *device) { return device_read_db_internal(device, false); } -DeviceAction device_action_from_string(const char *s) _pure_; -const char *device_action_to_string(DeviceAction a) _const_; +sd_device_action_t device_action_from_string(const char *s) _pure_; +const char *device_action_to_string(sd_device_action_t a) _const_; void dump_device_action_table(void); diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index a3a498f9e24..bf9397c03d2 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -43,7 +43,7 @@ int device_new_aux(sd_device **ret) { .devmode = (mode_t) -1, .devuid = (uid_t) -1, .devgid = (gid_t) -1, - .action = _DEVICE_ACTION_INVALID, + .action = _SD_DEVICE_ACTION_INVALID, }; *ret = device; @@ -316,6 +316,22 @@ _public_ int sd_device_new_from_subsystem_sysname(sd_device **ret, const char *s return -ENODEV; } +_public_ int sd_device_new_from_stat_rdev(sd_device **ret, const struct stat *st) { + char type; + + assert_return(ret, -EINVAL); + assert_return(st, -EINVAL); + + if (S_ISBLK(st->st_mode)) + type = 'b'; + else if (S_ISCHR(st->st_mode)) + type = 'c'; + else + return -ENOTTY; + + return sd_device_new_from_devnum(ret, type, st->st_rdev); +} + int device_set_devtype(sd_device *device, const char *devtype) { _cleanup_free_ char *t = NULL; int r; @@ -1052,6 +1068,30 @@ _public_ int sd_device_get_sysnum(sd_device *device, const char **ret) { return 0; } +_public_ int sd_device_get_action(sd_device *device, sd_device_action_t *ret) { + assert_return(device, -EINVAL); + + if (device->action < 0) + return -ENOENT; + + if (ret) + *ret = device->action; + + return 0; +} + +_public_ int sd_device_get_seqnum(sd_device *device, uint64_t *ret) { + assert_return(device, -EINVAL); + + if (device->seqnum == 0) + return -ENOENT; + + if (ret) + *ret = device->seqnum; + + return 0; +} + static bool is_valid_tag(const char *tag) { assert(tag); diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c index 34543a8b2ed..67f4b48da11 100644 --- a/src/libudev/libudev-device.c +++ b/src/libudev/libudev-device.c @@ -82,7 +82,7 @@ _public_ unsigned long long udev_device_get_seqnum(struct udev_device *udev_devi assert_return_errno(udev_device, 0, EINVAL); - if (device_get_seqnum(udev_device->device, &seqnum) < 0) + if (sd_device_get_seqnum(udev_device->device, &seqnum) < 0) return 0; return seqnum; @@ -693,11 +693,11 @@ _public_ struct udev_list_entry *udev_device_get_properties_list_entry(struct ud * Returns: the kernel action value, or #NULL if there is no action value available. **/ _public_ const char *udev_device_get_action(struct udev_device *udev_device) { - DeviceAction action; + sd_device_action_t action; assert_return_errno(udev_device, NULL, EINVAL); - if (device_get_action(udev_device->device, &action) < 0) + if (sd_device_get_action(udev_device->device, &action) < 0) return NULL; return device_action_to_string(action); diff --git a/src/login/logind-core.c b/src/login/logind-core.c index 3595d7a7732..2ecf2120fdb 100644 --- a/src/login/logind-core.c +++ b/src/login/logind-core.c @@ -246,7 +246,7 @@ int manager_process_seat_device(Manager *m, sd_device *d) { assert(m); - if (device_for_action(d, DEVICE_ACTION_REMOVE) || + if (device_for_action(d, SD_DEVICE_REMOVE) || sd_device_has_current_tag(d, "seat") <= 0) { const char *syspath; @@ -317,7 +317,7 @@ int manager_process_button_device(Manager *m, sd_device *d) { if (r < 0) return r; - if (device_for_action(d, DEVICE_ACTION_REMOVE) || + if (device_for_action(d, SD_DEVICE_REMOVE) || sd_device_has_current_tag(d, "power-switch") <= 0) { b = hashmap_get(m->buttons, sysname); diff --git a/src/login/logind.c b/src/login/logind.c index 3dae6955548..dac0bd2728d 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -578,7 +578,7 @@ static int manager_dispatch_vcsa_udev(sd_device_monitor *monitor, sd_device *dev if (sd_device_get_sysname(device, &name) >= 0 && startswith(name, "vcsa") && - device_for_action(device, DEVICE_ACTION_REMOVE)) + device_for_action(device, SD_DEVICE_REMOVE)) seat_preallocate_vts(m->seat0); return 0; diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index 70c5c30b30e..a6f343a1f63 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -182,15 +182,15 @@ int manager_connect_bus(Manager *m) { } static int manager_udev_process_link(sd_device_monitor *monitor, sd_device *device, void *userdata) { + sd_device_action_t action; Manager *m = userdata; - DeviceAction action; Link *link = NULL; int r, ifindex; assert(m); assert(device); - r = device_get_action(device, &action); + r = sd_device_get_action(device, &action); if (r < 0) { log_device_debug_errno(device, r, "Failed to get udev action, ignoring device: %m"); return 0; @@ -199,7 +199,7 @@ static int manager_udev_process_link(sd_device_monitor *monitor, sd_device *devi /* Ignore the "remove" uevent — let's remove a device only if rtnetlink says so. All other uevents * are "positive" events in some form, i.e. inform us about a changed or new network interface, that * still exists — and we are interested in that. */ - if (action == DEVICE_ACTION_REMOVE) + if (action == SD_DEVICE_REMOVE) return 0; r = sd_device_get_ifindex(device, &ifindex); diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index 2799f4f268e..6d24c3fd9ff 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -247,7 +247,7 @@ static int device_monitor_handler(sd_device_monitor *monitor, sd_device *device, assert(w); - if (device_for_action(device, DEVICE_ACTION_REMOVE)) + if (device_for_action(device, SD_DEVICE_REMOVE)) return 0; r = sd_device_get_parent(device, &pp); diff --git a/src/shared/udev-util.c b/src/shared/udev-util.c index 61decb80fa2..3a3f0198fdb 100644 --- a/src/shared/udev-util.c +++ b/src/shared/udev-util.c @@ -7,6 +7,7 @@ #include "alloc-util.h" #include "device-nodes.h" +#include "device-private.h" #include "device-util.h" #include "env-file.h" #include "escape.h" @@ -175,7 +176,7 @@ static int device_monitor_handler(sd_device_monitor *monitor, sd_device *device, * (And yes, we only need to special case REMOVE. It's the only "negative" event type, where a device * ceases to exist. All other event types are "positive": the device exists and is registered in the * udev database, thus whenever we see the event, we can consider it initialized.) */ - if (device_for_action(device, DEVICE_ACTION_REMOVE)) + if (device_for_action(device, SD_DEVICE_REMOVE)) return 0; if (data->sysname && sd_device_get_sysname(device, &sysname) >= 0 && streq(sysname, data->sysname)) @@ -318,26 +319,29 @@ int device_is_renaming(sd_device *dev) { return true; } -bool device_for_action(sd_device *dev, DeviceAction action) { - DeviceAction a; +bool device_for_action(sd_device *dev, sd_device_action_t a) { + sd_device_action_t b; assert(dev); - if (device_get_action(dev, &a) < 0) + if (a < 0) return false; - return a == action; + if (sd_device_get_action(dev, &b) < 0) + return false; + + return a == b; } void log_device_uevent(sd_device *device, const char *str) { - DeviceAction action = _DEVICE_ACTION_INVALID; + sd_device_action_t action = _SD_DEVICE_ACTION_INVALID; uint64_t seqnum = 0; if (!DEBUG_LOGGING) return; - (void) device_get_seqnum(device, &seqnum); - (void) device_get_action(device, &action); + (void) sd_device_get_seqnum(device, &seqnum); + (void) sd_device_get_action(device, &action); log_device_debug(device, "%s%s(SEQNUM=%"PRIu64", ACTION=%s)", strempty(str), isempty(str) ? "" : " ", seqnum, strna(device_action_to_string(action))); diff --git a/src/shared/udev-util.h b/src/shared/udev-util.h index 5fce03b25f3..c2cf7caa670 100644 --- a/src/shared/udev-util.h +++ b/src/shared/udev-util.h @@ -3,7 +3,6 @@ #include "sd-device.h" -#include "device-private.h" #include "time-util.h" #define UDEV_NAME_SIZE 512 @@ -35,7 +34,8 @@ static inline int udev_parse_config(void) { int device_wait_for_initialization(sd_device *device, const char *subsystem, usec_t deadline, sd_device **ret); int device_wait_for_devlink(const char *path, const char *subsystem, usec_t deadline, sd_device **ret); int device_is_renaming(sd_device *dev); -bool device_for_action(sd_device *dev, DeviceAction action); + +bool device_for_action(sd_device *dev, sd_device_action_t action); void log_device_uevent(sd_device *device, const char *str); diff --git a/src/systemd/sd-device.h b/src/systemd/sd-device.h index 78fe5841609..af0e26e2d76 100644 --- a/src/systemd/sd-device.h +++ b/src/systemd/sd-device.h @@ -17,7 +17,9 @@ along with systemd; If not, see . ***/ +#include #include +#include #include #include @@ -31,6 +33,20 @@ typedef struct sd_device sd_device; typedef struct sd_device_enumerator sd_device_enumerator; typedef struct sd_device_monitor sd_device_monitor; +typedef enum sd_device_action_t { + SD_DEVICE_ADD, + SD_DEVICE_REMOVE, + SD_DEVICE_CHANGE, + SD_DEVICE_MOVE, + SD_DEVICE_ONLINE, + SD_DEVICE_OFFLINE, + SD_DEVICE_BIND, + SD_DEVICE_UNBIND, + _SD_DEVICE_ACTION_MAX, + _SD_DEVICE_ACTION_INVALID = -EINVAL, + _SD_ENUM_FORCE_S64(DEVICE_ACTION), +} sd_device_action_t; + /* callback */ typedef int (*sd_device_monitor_handler_t)(sd_device_monitor *m, sd_device *device, void *userdata); @@ -44,6 +60,7 @@ int sd_device_new_from_syspath(sd_device **ret, const char *syspath); int sd_device_new_from_devnum(sd_device **ret, char type, dev_t devnum); int sd_device_new_from_subsystem_sysname(sd_device **ret, const char *subsystem, const char *sysname); int sd_device_new_from_device_id(sd_device **ret, const char *id); +int sd_device_new_from_stat_rdev(sd_device **ret, const struct stat *st); int sd_device_get_parent(sd_device *child, sd_device **ret); int sd_device_get_parent_with_subsystem_devtype(sd_device *child, const char *subsystem, const char *devtype, sd_device **ret); @@ -58,6 +75,8 @@ int sd_device_get_devpath(sd_device *device, const char **ret); int sd_device_get_devname(sd_device *device, const char **ret); int sd_device_get_sysname(sd_device *device, const char **ret); int sd_device_get_sysnum(sd_device *device, const char **ret); +int sd_device_get_action(sd_device *device, sd_device_action_t *ret); +int sd_device_get_seqnum(sd_device *device, uint64_t *ret); int sd_device_get_is_initialized(sd_device *device); int sd_device_get_usec_since_initialized(sd_device *device, uint64_t *usec); diff --git a/src/test/test-tables.c b/src/test/test-tables.c index cc93bbbc749..3e5df045900 100644 --- a/src/test/test-tables.c +++ b/src/test/test-tables.c @@ -50,7 +50,7 @@ int main(int argc, char **argv) { test_table(collect_mode, COLLECT_MODE); test_table(condition_result, CONDITION_RESULT); test_table(condition_type, CONDITION_TYPE); - test_table(device_action, DEVICE_ACTION); + test_table(device_action, SD_DEVICE_ACTION); test_table(device_state, DEVICE_STATE); test_table(dns_over_tls_mode, DNS_OVER_TLS_MODE); test_table(dnssec_mode, DNSSEC_MODE); @@ -125,5 +125,7 @@ int main(int argc, char **argv) { test_table_sparse(object_compressed, OBJECT_COMPRESSED); + assert_cc(sizeof(sd_device_action_t) == sizeof(int64_t)); + return EXIT_SUCCESS; } diff --git a/src/udev/fido_id/fido_id.c b/src/udev/fido_id/fido_id.c index f14b81d30df..a9f5f8f8a64 100644 --- a/src/udev/fido_id/fido_id.c +++ b/src/udev/fido_id/fido_id.c @@ -14,7 +14,6 @@ #include #include -#include "device-internal.h" #include "device-private.h" #include "device-util.h" #include "fd-util.h" diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index f2ca1bb5610..10d64d52608 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -594,7 +594,7 @@ static int link_config_apply_alternative_names(sd_netlink **rtnl, const link_con int link_config_apply(link_config_ctx *ctx, const link_config *config, sd_device *device, const char **ret_name) { const char *new_name; - DeviceAction a; + sd_device_action_t a; int r; assert(ctx); @@ -602,11 +602,11 @@ int link_config_apply(link_config_ctx *ctx, const link_config *config, sd_device assert(device); assert(ret_name); - r = device_get_action(device, &a); + r = sd_device_get_action(device, &a); if (r < 0) return log_device_error_errno(device, r, "Failed to get ACTION= property: %m"); - if (!IN_SET(a, DEVICE_ACTION_ADD, DEVICE_ACTION_BIND, DEVICE_ACTION_MOVE)) { + if (!IN_SET(a, SD_DEVICE_ADD, SD_DEVICE_BIND, SD_DEVICE_MOVE)) { log_device_debug(device, "Skipping to apply .link settings on '%s' uevent.", device_action_to_string(a)); r = sd_device_get_sysname(device, ret_name); @@ -624,7 +624,7 @@ int link_config_apply(link_config_ctx *ctx, const link_config *config, sd_device if (r < 0) return r; - if (a == DEVICE_ACTION_MOVE) { + if (a == SD_DEVICE_MOVE) { log_device_debug(device, "Skipping to apply Name= and NamePolicy= on '%s' uevent.", device_action_to_string(a)); r = sd_device_get_sysname(device, &new_name); diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index 8aeaf92e41c..78a999d00a1 100644 --- a/src/udev/udev-event.c +++ b/src/udev/udev-event.c @@ -831,7 +831,7 @@ static int rename_netif(UdevEvent *event) { if (streq(event->name, oldname)) return 0; /* The interface name is already requested name. */ - if (!device_for_action(dev, DEVICE_ACTION_ADD)) + if (!device_for_action(dev, SD_DEVICE_ADD)) return 0; /* Rename the interface only when it is added. */ r = sd_device_get_ifindex(dev, &ifindex); @@ -904,7 +904,7 @@ static int update_devnode(UdevEvent *event) { /* If group is set, but mode is not set, "upgrade" mode for the group. */ event->mode = 0660; - bool apply_mac = device_for_action(dev, DEVICE_ACTION_ADD); + bool apply_mac = device_for_action(dev, SD_DEVICE_ADD); return udev_node_add(dev, apply_mac, event->mode, event->uid, event->gid, event->seclabel_list); } @@ -975,7 +975,7 @@ int udev_event_execute_rules(UdevEvent *event, Hashmap *properties_list, UdevRules *rules) { const char *subsystem; - DeviceAction action; + sd_device_action_t action; sd_device *dev; int r; @@ -988,11 +988,11 @@ int udev_event_execute_rules(UdevEvent *event, if (r < 0) return log_device_error_errno(dev, r, "Failed to get subsystem: %m"); - r = device_get_action(dev, &action); + r = sd_device_get_action(dev, &action); if (r < 0) return log_device_error_errno(dev, r, "Failed to get ACTION: %m"); - if (action == DEVICE_ACTION_REMOVE) { + if (action == SD_DEVICE_REMOVE) { event_execute_rules_on_remove(event, timeout_usec, timeout_signal, properties_list, rules); return 0; } @@ -1009,7 +1009,7 @@ int udev_event_execute_rules(UdevEvent *event, /* Disable watch during event processing. */ (void) udev_watch_end(event->dev_db_clone); - if (action == DEVICE_ACTION_MOVE) { + if (action == SD_DEVICE_MOVE) { r = udev_event_on_move(event->dev); if (r < 0) return r; diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 78184b4136d..0f10116a997 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -6,6 +6,7 @@ #include "architecture.h" #include "conf-files.h" #include "def.h" +#include "device-private.h" #include "device-util.h" #include "dirent-util.h" #include "escape.h" @@ -1545,9 +1546,9 @@ static int udev_rule_apply_token_to_event( switch (token->type) { case TK_M_ACTION: { - DeviceAction a; + sd_device_action_t a; - r = device_get_action(dev, &a); + r = sd_device_get_action(dev, &a); if (r < 0) return log_rule_error_errno(dev, rules, r, "Failed to get uevent action type: %m"); @@ -2226,14 +2227,14 @@ static int udev_rule_apply_line_to_event( UdevRuleLineType mask = LINE_HAS_GOTO | LINE_UPDATE_SOMETHING; UdevRuleToken *token, *next_token; bool parents_done = false; - DeviceAction action; + sd_device_action_t action; int r; - r = device_get_action(event->dev, &action); + r = sd_device_get_action(event->dev, &action); if (r < 0) return r; - if (action != DEVICE_ACTION_REMOVE) { + if (action != SD_DEVICE_REMOVE) { if (sd_device_get_devnum(event->dev, NULL) >= 0) mask |= LINE_HAS_DEVLINK; diff --git a/src/udev/udevadm-monitor.c b/src/udev/udevadm-monitor.c index 1a8a1a5b3b5..00b03c550d5 100644 --- a/src/udev/udevadm-monitor.c +++ b/src/udev/udevadm-monitor.c @@ -27,7 +27,7 @@ static Set *arg_tag_filter = NULL; static Hashmap *arg_subsystem_filter = NULL; static int device_monitor_handler(sd_device_monitor *monitor, sd_device *device, void *userdata) { - DeviceAction action = _DEVICE_ACTION_INVALID; + sd_device_action_t action = _SD_DEVICE_ACTION_INVALID; const char *devpath = NULL, *subsystem = NULL; MonitorNetlinkGroup group = PTR_TO_INT(userdata); struct timespec ts; @@ -35,7 +35,7 @@ static int device_monitor_handler(sd_device_monitor *monitor, sd_device *device, assert(device); assert(IN_SET(group, MONITOR_GROUP_UDEV, MONITOR_GROUP_KERNEL)); - (void) device_get_action(device, &action); + (void) sd_device_get_action(device, &action); (void) sd_device_get_devpath(device, &devpath); (void) sd_device_get_subsystem(device, &subsystem); diff --git a/src/udev/udevadm-test.c b/src/udev/udevadm-test.c index e28378eea81..bbee79c88e2 100644 --- a/src/udev/udevadm-test.c +++ b/src/udev/udevadm-test.c @@ -54,7 +54,7 @@ static int parse_argv(int argc, char *argv[]) { while ((c = getopt_long(argc, argv, "a:N:Vh", options, NULL)) >= 0) switch (c) { case 'a': { - DeviceAction a; + sd_device_action_t a; if (streq(optarg, "help")) { dump_device_action_table(); diff --git a/src/udev/udevadm-trigger.c b/src/udev/udevadm-trigger.c index a4588cb4e4f..908c27495f8 100644 --- a/src/udev/udevadm-trigger.c +++ b/src/udev/udevadm-trigger.c @@ -211,7 +211,7 @@ int trigger_main(int argc, char *argv[], void *userdata) { return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown type --type=%s", optarg); break; case 'c': { - DeviceAction a; + sd_device_action_t a; if (streq(optarg, "help")) { dump_device_action_table(); diff --git a/src/udev/udevadm-util.c b/src/udev/udevadm-util.c index 39d0c7eb3f1..10191d88ba9 100644 --- a/src/udev/udevadm-util.c +++ b/src/udev/udevadm-util.c @@ -20,7 +20,7 @@ static int find_device_from_path(const char *path, sd_device **ret) { if (stat(path, &st) < 0) return -errno; - return device_new_from_stat_rdev(ret, &st); + return sd_device_new_from_stat_rdev(ret, &st); } return -EINVAL; diff --git a/src/udev/udevd.c b/src/udev/udevd.c index 9772246aeb2..0657bf1b6da 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -325,16 +325,12 @@ static int worker_lock_block_device(sd_device *dev, int *ret_fd) { assert(dev); assert(ret_fd); - /* - * Take a shared lock on the device node; this establishes - * a concept of device "ownership" to serialize device - * access. External processes holding an exclusive lock will - * cause udev to skip the event handling; in the case udev - * acquired the lock, the external process can block until - * udev has finished its event handling. - */ + /* Take a shared lock on the device node; this establishes a concept of device "ownership" to + * serialize device access. External processes holding an exclusive lock will cause udev to skip the + * event handling; in the case udev acquired the lock, the external process can block until udev has + * finished its event handling. */ - if (device_for_action(dev, DEVICE_ACTION_REMOVE)) + if (device_for_action(dev, SD_DEVICE_REMOVE)) return 0; r = sd_device_get_subsystem(dev, &val); @@ -392,7 +388,7 @@ static int worker_mark_block_device_read_only(sd_device *dev) { /* Do this only once, when the block device is new. If the device is later retriggered let's not * toggle the bit again, so that people can boot up with full read-only mode and then unset the bit * for specific devices only. */ - if (!device_for_action(dev, DEVICE_ACTION_ADD)) + if (!device_for_action(dev, SD_DEVICE_ADD)) return 0; r = sd_device_get_subsystem(dev, &val); @@ -694,7 +690,7 @@ static int event_queue_insert(Manager *manager, sd_device *dev) { assert(manager->pid == getpid_cached()); /* We only accepts devices received by device monitor. */ - r = device_get_seqnum(dev, &seqnum); + r = sd_device_get_seqnum(dev, &seqnum); if (r < 0) return r;