]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: make udev_builtin_run() take UdevEvent*
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 16 May 2023 02:29:49 +0000 (11:29 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 16 May 2023 07:37:31 +0000 (16:37 +0900)
No functional change, preparation for later commits.

16 files changed:
src/udev/udev-builtin-blkid.c
src/udev/udev-builtin-btrfs.c
src/udev/udev-builtin-hwdb.c
src/udev/udev-builtin-input_id.c
src/udev/udev-builtin-keyboard.c
src/udev/udev-builtin-kmod.c
src/udev/udev-builtin-net_id.c
src/udev/udev-builtin-net_setup_link.c
src/udev/udev-builtin-path_id.c
src/udev/udev-builtin-uaccess.c
src/udev/udev-builtin-usb_id.c
src/udev/udev-builtin.c
src/udev/udev-builtin.h
src/udev/udev-event.c
src/udev/udev-rules.c
src/udev/udevadm-test-builtin.c

index 2b2205513b11c0ef3b97d0013e2a4be75f8c2049..11419a3e6113b85635b9b7b7bb7018169dbaf7b0 100644 (file)
@@ -315,7 +315,8 @@ notloop:
         return 0;
 }
 
-static int builtin_blkid(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test) {
+static int builtin_blkid(UdevEvent *event, int argc, char *argv[], bool test) {
+        sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
         const char *devnode, *root_partition = NULL, *data, *name;
         _cleanup_(blkid_free_probep) blkid_probe pr = NULL;
         _cleanup_free_ char *backing_fname = NULL;
index 79f91ea2ae52184d6cf0fdef8616858392adea74..9b12aebb3ad4bc46b5e93bee994fcb63b6045ff0 100644 (file)
@@ -12,7 +12,8 @@
 #include "strxcpyx.h"
 #include "udev-builtin.h"
 
-static int builtin_btrfs(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test) {
+static int builtin_btrfs(UdevEvent *event, int argc, char *argv[], bool test) {
+        sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
         struct btrfs_ioctl_vol_args args = {};
         _cleanup_close_ int fd = -EBADF;
         int r;
index 8d652e46feebdbf0bc9635ea3e146412be54e4c4..19e07e734f1afea6e73cc9c80f56255d816149fa 100644 (file)
@@ -118,7 +118,7 @@ next:
         return r;
 }
 
-static int builtin_hwdb(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test) {
+static int builtin_hwdb(UdevEvent *event, int argc, char *argv[], bool test) {
         static const struct option options[] = {
                 { "filter", required_argument, NULL, 'f' },
                 { "device", required_argument, NULL, 'd' },
@@ -131,6 +131,7 @@ static int builtin_hwdb(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[
         const char *subsystem = NULL;
         const char *prefix = NULL;
         _cleanup_(sd_device_unrefp) sd_device *srcdev = NULL;
+        sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
         int r;
 
         if (!hwdb)
index 540f39053038491b4bd9cfb8ea7c445b241599cd..295e8d215940e2926a6edac996175d84b6e94611 100644 (file)
@@ -369,8 +369,8 @@ static bool test_key(sd_device *dev,
         return found;
 }
 
-static int builtin_input_id(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test) {
-        sd_device *pdev;
+static int builtin_input_id(UdevEvent *event, int argc, char *argv[], bool test) {
+        sd_device *pdev, *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
         unsigned long bitmask_ev[NBITS(EV_MAX)];
         unsigned long bitmask_abs[NBITS(ABS_MAX)];
         unsigned long bitmask_key[NBITS(KEY_MAX)];
@@ -380,8 +380,6 @@ static int builtin_input_id(sd_device *dev, sd_netlink **rtnl, int argc, char *a
         bool is_pointer;
         bool is_key;
 
-        assert(dev);
-
         /* walk up the parental chain until we find the real input device; the
          * argument is very likely a subdevice of this, like eventN */
         for (pdev = dev; pdev; ) {
index 80cfdee0c188e99099b0a261927c773747b4552a..da67c2be1c866ce117d2fb16c624ef05b7e928db 100644 (file)
@@ -159,7 +159,8 @@ static int set_trackpoint_sensitivity(sd_device *dev, const char *value) {
         return 0;
 }
 
-static int builtin_keyboard(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test) {
+static int builtin_keyboard(UdevEvent *event, int argc, char *argv[], bool test) {
+        sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
         unsigned release[1024];
         unsigned release_count = 0;
         _cleanup_close_ int fd = -EBADF;
index eade042f3514f692f9ee7d02cb88516eb801fa01..3ab5c485f80d79fc3c6b58c7b980998ced9e3ad7 100644 (file)
@@ -22,11 +22,10 @@ _printf_(6,0) static void udev_kmod_log(void *data, int priority, const char *fi
         log_internalv(priority, 0, file, line, fn, format, args);
 }
 
-static int builtin_kmod(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test) {
+static int builtin_kmod(UdevEvent *event, int argc, char *argv[], bool test) {
+        sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
         int r;
 
-        assert(dev);
-
         if (!ctx)
                 return 0;
 
index 5e2b69d6f74d001ebec3df092789e5d7ebd8e79f..998478ec4eb18b83d454e6c1df17f5b8459a4797 100644 (file)
@@ -1096,7 +1096,8 @@ static int get_link_info(sd_device *dev, LinkInfo *info) {
         return 0;
 }
 
-static int builtin_net_id(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test) {
+static int builtin_net_id(UdevEvent *event, int argc, char *argv[], bool test) {
+        sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
         const char *prefix;
         NetNames names = {};
         LinkInfo info = {};
index 18450536b5caefb3d0c39460d88efcc6b652978b..84a0a6ef3fbe15fc08abf03c5f300c22f62ad996 100644 (file)
@@ -12,7 +12,8 @@
 
 static LinkConfigContext *ctx = NULL;
 
-static int builtin_net_setup_link(sd_device *dev, sd_netlink **rtnl, int argc, char **argv, bool test) {
+static int builtin_net_setup_link(UdevEvent *event, int argc, char **argv, bool test) {
+        sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
         _cleanup_(link_freep) Link *link = NULL;
         _cleanup_free_ char *joined = NULL;
         int r;
@@ -20,7 +21,7 @@ static int builtin_net_setup_link(sd_device *dev, sd_netlink **rtnl, int argc, c
         if (argc > 1)
                 return log_device_error_errno(dev, SYNTHETIC_ERRNO(EINVAL), "This program takes no arguments.");
 
-        r = link_new(ctx, rtnl, dev, &link);
+        r = link_new(ctx, &event->rtnl, dev, &link);
         if (r == -ENODEV) {
                 log_device_debug_errno(dev, r, "Link vanished while getting information, ignoring.");
                 return 0;
@@ -41,7 +42,7 @@ static int builtin_net_setup_link(sd_device *dev, sd_netlink **rtnl, int argc, c
                 return log_device_error_errno(dev, r, "Failed to get link config: %m");
         }
 
-        r = link_apply_config(ctx, rtnl, link);
+        r = link_apply_config(ctx, &event->rtnl, link);
         if (r == -ENODEV)
                 log_device_debug_errno(dev, r, "Link vanished while applying configuration, ignoring.");
         else if (r < 0)
index ff6682cad9532c05e04ba51eccafe95e380cb8f6..404196f409e76b21572cbed8584c11b59b231224 100644 (file)
@@ -589,15 +589,14 @@ static int find_real_nvme_parent(sd_device *dev, sd_device **ret) {
         return 0;
 }
 
-static int builtin_path_id(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test) {
+static int builtin_path_id(UdevEvent *event, int argc, char *argv[], bool test) {
+        sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
         _cleanup_(sd_device_unrefp) sd_device *dev_other_branch = NULL;
         _cleanup_free_ char *path = NULL, *compat_path = NULL;
         bool supported_transport = false, supported_parent = false;
         const char *subsystem;
         int r;
 
-        assert(dev);
-
         /* walk up the chain of devices and compose path */
         for (sd_device *parent = dev; parent; ) {
                 const char *subsys, *sysname;
index 6e73d9937550a3904af384047237028000dd4d3b..36c993cbb0839dd7167dbb196604e6fee9293793 100644 (file)
@@ -16,7 +16,8 @@
 #include "log.h"
 #include "udev-builtin.h"
 
-static int builtin_uaccess(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test) {
+static int builtin_uaccess(UdevEvent *event, int argc, char *argv[], bool test) {
+        sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
         const char *path = NULL, *seat;
         bool changed_acl = false;
         uid_t uid;
index 91deb64292e81c01406abd9ba2509a722cb64c9c..8e83c9c3426615960c3308c110daf4a3505fea93 100644 (file)
@@ -224,7 +224,8 @@ static int dev_if_packed_info(sd_device *dev, char *ifs_str, size_t len) {
  * 6.) If the device supplies a serial number, this number
  *     is concatenated with the identification with an underscore '_'.
  */
-static int builtin_usb_id(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test) {
+static int builtin_usb_id(UdevEvent *event, int argc, char *argv[], bool test) {
+        sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
         char vendor_str[64] = "";
         char vendor_str_enc[256];
         const char *vendor_id;
@@ -250,8 +251,6 @@ static int builtin_usb_id(sd_device *dev, sd_netlink **rtnl, int argc, char *arg
         const char *syspath, *sysname, *devtype, *interface_syspath;
         int r;
 
-        assert(dev);
-
         r = sd_device_get_syspath(dev, &syspath);
         if (r < 0)
                 return r;
index 566641e4007f925543d4d4916a955f85534f24cd..a8dd656b00bf728bb64f38947cb10dd7b469cbef 100644 (file)
@@ -98,11 +98,12 @@ UdevBuiltinCommand udev_builtin_lookup(const char *command) {
         return _UDEV_BUILTIN_INVALID;
 }
 
-int udev_builtin_run(sd_device *dev, sd_netlink **rtnl, UdevBuiltinCommand cmd, const char *command, bool test) {
+int udev_builtin_run(UdevEvent *event, UdevBuiltinCommand cmd, const char *command, bool test) {
         _cleanup_strv_free_ char **argv = NULL;
         int r;
 
-        assert(dev);
+        assert(event);
+        assert(event->dev);
         assert(cmd >= 0 && cmd < _UDEV_BUILTIN_MAX);
         assert(command);
 
@@ -115,7 +116,7 @@ int udev_builtin_run(sd_device *dev, sd_netlink **rtnl, UdevBuiltinCommand cmd,
 
         /* we need '0' here to reset the internal state */
         optind = 0;
-        return builtins[cmd]->cmd(dev, rtnl, strv_length(argv), argv, test);
+        return builtins[cmd]->cmd(event, strv_length(argv), argv, test);
 }
 
 int udev_builtin_add_property(sd_device *dev, bool test, const char *key, const char *val) {
index 490b2dbe96af67632e41ea3e1a3f0e5ce8527502..b2cf81ad312a8597b4781a7c8ab9db89416c9cbd 100644 (file)
@@ -7,6 +7,7 @@
 #include "sd-netlink.h"
 
 #include "macro.h"
+#include "udev-event.h"
 
 typedef enum UdevBuiltinCommand {
 #if HAVE_BLKID
@@ -32,7 +33,7 @@ typedef enum UdevBuiltinCommand {
 
 typedef struct UdevBuiltin {
         const char *name;
-        int (*cmd)(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test);
+        int (*cmd)(UdevEvent *event, int argc, char *argv[], bool test);
         const char *help;
         int (*init)(void);
         void (*exit)(void);
@@ -76,7 +77,7 @@ void udev_builtin_exit(void);
 UdevBuiltinCommand udev_builtin_lookup(const char *command);
 const char *udev_builtin_name(UdevBuiltinCommand cmd);
 bool udev_builtin_run_once(UdevBuiltinCommand cmd);
-int udev_builtin_run(sd_device *dev, sd_netlink **rtnl, UdevBuiltinCommand cmd, const char *command, bool test);
+int udev_builtin_run(UdevEvent *event, UdevBuiltinCommand cmd, const char *command, bool test);
 void udev_builtin_list(void);
 bool udev_builtin_should_reload(void);
 int udev_builtin_add_property(sd_device *dev, bool test, const char *key, const char *val);
index a8d7db40b457214cc94bea7310944d6a95a0f92f..88b01f4e1b61dfc7324a9091ae7dc24ec742a11f 100644 (file)
@@ -1185,7 +1185,7 @@ void udev_event_execute_run(UdevEvent *event, usec_t timeout_usec, int timeout_s
 
                 if (builtin_cmd != _UDEV_BUILTIN_INVALID) {
                         log_device_debug(event->dev, "Running built-in command \"%s\"", command);
-                        r = udev_builtin_run(event->dev, &event->rtnl, builtin_cmd, command, false);
+                        r = udev_builtin_run(event, builtin_cmd, command, false);
                         if (r < 0)
                                 log_device_debug_errno(event->dev, r, "Failed to run built-in command \"%s\", ignoring: %m", command);
                 } else {
index d6e701f3cc3248a9348196dc679f15b7351706f1..fc1ef34964ec6da3408cb96b5ffe8e2c5cd49376 100644 (file)
@@ -2193,7 +2193,7 @@ static int udev_rule_apply_token_to_event(
 
                 log_event_debug(dev, token, "Importing properties from results of builtin command '%s'", buf);
 
-                r = udev_builtin_run(dev, &event->rtnl, cmd, buf, false);
+                r = udev_builtin_run(event, cmd, buf, false);
                 if (r < 0) {
                         /* remember failure */
                         log_event_debug_errno(dev, token, r, "Failed to run builtin '%s': %m", buf);
index 5570eec789845efa15a0857214aa84df026c30b3..5d1fafbd0390a56bc6bc627d4fd71f79b1f0a5bc 100644 (file)
@@ -72,7 +72,7 @@ static int parse_argv(int argc, char *argv[]) {
 }
 
 int builtin_main(int argc, char *argv[], void *userdata) {
-        _cleanup_(sd_netlink_unrefp) sd_netlink *rtnl = NULL;
+        _cleanup_(udev_event_freep) UdevEvent *event = NULL;
         _cleanup_(sd_device_unrefp) sd_device *dev = NULL;
         UdevBuiltinCommand cmd;
         int r;
@@ -97,7 +97,13 @@ int builtin_main(int argc, char *argv[], void *userdata) {
                 goto finish;
         }
 
-        r = udev_builtin_run(dev, &rtnl, cmd, arg_command, true);
+        event = udev_event_new(dev, 0, NULL, LOG_DEBUG);
+        if (!event) {
+                r = log_oom();
+                goto finish;
+        }
+
+        r = udev_builtin_run(event, cmd, arg_command, true);
         if (r < 0)
                 log_debug_errno(r, "Builtin command '%s' fails: %m", arg_command);