diff options
27 files changed, 156 insertions, 146 deletions
diff --git a/src/core/device.c b/src/core/device.c index db39479c8f..356c389c55 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 5746940fa8..a81b1928b8 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 1b13002627..f0c844b0cb 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 3de3b4e26f..823cf0a25f 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 f9970a2e52..fbe9803d42 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 3321c8e2dc..c1a81e3b41 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 e37575d3b9..b14f43aae5 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; @@ -355,7 +331,12 @@ static int device_amend(sd_device *device, const char *key, const char *value) { return 0; } -static int device_append(sd_device *device, char *key, const char **_major, const char **_minor) { +static int device_append( + sd_device *device, + char *key, + const char **_major, + const char **_minor) { + const char *major = NULL, *minor = NULL; char *value; int r; @@ -384,10 +365,10 @@ static int device_append(sd_device *device, char *key, const char **_major, cons return r; } - if (major != 0) + if (major) *_major = major; - if (minor != 0) + if (minor) *_minor = minor; return 0; @@ -719,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; @@ -998,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 e8bf2f547e..ec76f772e5 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 a3a498f9e2..bf9397c03d 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 34543a8b2e..67f4b48da1 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 3595d7a773..2ecf2120fd 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 3dae695554..dac0bd2728 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 70c5c30b30..a6f343a1f6 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 2799f4f268..6d24c3fd9f 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 61decb80fa..3a3f0198fd 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 5fce03b25f..c2cf7caa67 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 78fe584160..af0e26e2d7 100644 --- a/src/systemd/sd-device.h +++ b/src/systemd/sd-device.h @@ -17,7 +17,9 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ +#include <errno.h> #include <inttypes.h> +#include <sys/stat.h> #include <sys/sysmacros.h> #include <sys/types.h> @@ -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 cc93bbbc74..3e5df04590 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 f14b81d30d..a9f5f8f8a6 100644 --- a/src/udev/fido_id/fido_id.c +++ b/src/udev/fido_id/fido_id.c @@ -14,7 +14,6 @@ #include <sys/types.h> #include <unistd.h> -#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 f2ca1bb561..10d64d5260 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 8aeaf92e41..78a999d00a 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 78184b4136..0f10116a99 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 1a8a1a5b3b..00b03c550d 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 e28378eea8..7a30e25135 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(); @@ -63,10 +63,9 @@ static int parse_argv(int argc, char *argv[]) { a = device_action_from_string(optarg); if (a < 0) - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), - "Invalid action '%s'", optarg); + return log_error_errno(a, "Invalid action '%s'", optarg); - arg_action = optarg; + arg_action = device_action_to_string(a); break; } case 'N': diff --git a/src/udev/udevadm-trigger.c b/src/udev/udevadm-trigger.c index a4588cb4e4..2d16f34d86 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(); @@ -222,7 +222,7 @@ int trigger_main(int argc, char *argv[], void *userdata) { if (a < 0) return log_error_errno(a, "Unknown action '%s'", optarg); - action = optarg; + action = device_action_to_string(a); break; } case 's': diff --git a/src/udev/udevadm-util.c b/src/udev/udevadm-util.c index 39d0c7eb3f..10191d88ba 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 9772246aeb..0657bf1b6d 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; |