]> err.no Git - systemd/commitdiff
invalidate rules and kmod index with 'udevadm control --reload'
authorKay Sievers <kay.sievers@vrfy.org>
Sun, 25 Dec 2011 15:37:15 +0000 (16:37 +0100)
committerKay Sievers <kay.sievers@vrfy.org>
Sun, 25 Dec 2011 15:37:15 +0000 (16:37 +0100)
  - rename --reload-rules to --reload
  - invalidate rules and databases only, delay parsing to the next event
  - enable debug output for test-builtin

udev/udev-builtin-kmod.c
udev/udev-ctrl.c
udev/udev-rules.c
udev/udev.h
udev/udevadm-control.c
udev/udevadm-test-builtin.c
udev/udevadm.xml
udev/udevd.c

index 8e7a50a02046e4978ac159c7a63567a298054d77..6f3e2589c242333e895de79e0522db4edff754b4 100644 (file)
@@ -321,11 +321,17 @@ static int builtin_kmod(struct udev_device *dev, int argc, char *argv[], bool te
        struct udev *udev = udev_device_get_udev(dev);
        int i;
 
-       if (!ctx)
-               return EXIT_FAILURE;
+       if (!ctx) {
+               ctx = kmod_new(NULL, NULL);
+               if (!ctx)
+                       return -ENOMEM;
 
-       if (argc < 3) {
-               err(udev, "missing command + argument\n");
+               info(udev, "load module index\n");
+               kmod_load_resources(ctx);
+       }
+
+       if (argc < 3 || strcmp(argv[1], "load")) {
+               err(udev, "expect: %s load <module>\n", argv[0]);
                return EXIT_FAILURE;
        }
 
@@ -339,12 +345,15 @@ static int builtin_kmod(struct udev_device *dev, int argc, char *argv[], bool te
 
 static int builtin_kmod_init(struct udev *udev)
 {
-       kmod_unref(ctx);
+       if (ctx)
+               return 0;
+
        ctx = kmod_new(NULL, NULL);
        if (!ctx)
                return -ENOMEM;
 
        info(udev, "load module index\n");
+       kmod_load_resources(ctx);
        return 0;
 }
 
index e4348c314d4b2632cf2e755072daee547aae608e..fab1108de0a6171415c63204e214a864ca99e01a 100644 (file)
@@ -30,7 +30,7 @@ enum udev_ctrl_msg_type {
        UDEV_CTRL_SET_LOG_LEVEL,
        UDEV_CTRL_STOP_EXEC_QUEUE,
        UDEV_CTRL_START_EXEC_QUEUE,
-       UDEV_CTRL_RELOAD_RULES,
+       UDEV_CTRL_RELOAD,
        UDEV_CTRL_SET_ENV,
        UDEV_CTRL_SET_CHILDREN_MAX,
        UDEV_CTRL_PING,
@@ -310,9 +310,9 @@ int udev_ctrl_send_start_exec_queue(struct udev_ctrl *uctrl, int timeout)
        return ctrl_send(uctrl, UDEV_CTRL_START_EXEC_QUEUE, 0, NULL, timeout);
 }
 
-int udev_ctrl_send_reload_rules(struct udev_ctrl *uctrl, int timeout)
+int udev_ctrl_send_reload(struct udev_ctrl *uctrl, int timeout)
 {
-       return ctrl_send(uctrl, UDEV_CTRL_RELOAD_RULES, 0, NULL, timeout);
+       return ctrl_send(uctrl, UDEV_CTRL_RELOAD, 0, NULL, timeout);
 }
 
 int udev_ctrl_send_set_env(struct udev_ctrl *uctrl, const char *key, int timeout)
@@ -458,9 +458,9 @@ int udev_ctrl_get_start_exec_queue(struct udev_ctrl_msg *ctrl_msg)
        return -1;
 }
 
-int udev_ctrl_get_reload_rules(struct udev_ctrl_msg *ctrl_msg)
+int udev_ctrl_get_reload(struct udev_ctrl_msg *ctrl_msg)
 {
-       if (ctrl_msg->ctrl_msg_wire.type == UDEV_CTRL_RELOAD_RULES)
+       if (ctrl_msg->ctrl_msg_wire.type == UDEV_CTRL_RELOAD)
                return 1;
        return -1;
 }
index 4226d0b4e0ea801439765db624131ffeb960cf00..aa750219daaa8dc5c513c0f3323e90a417bfe936 100644 (file)
@@ -1890,16 +1890,17 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names)
        return rules;
 }
 
-void udev_rules_unref(struct udev_rules *rules)
+struct udev_rules *udev_rules_unref(struct udev_rules *rules)
 {
        if (rules == NULL)
-               return;
+               return NULL;
        free(rules->tokens);
        free(rules->buf);
        free(rules->trie_nodes);
        free(rules->uids);
        free(rules->gids);
        free(rules);
+       return NULL;
 }
 
 static int match_key(struct udev_rules *rules, struct token *token, const char *val)
index 430958a457407834f0c921556831db95e9761ecb..7bd2228a6b6267f5c6467f9a331f175e0c78e956 100644 (file)
@@ -66,7 +66,7 @@ struct udev_watch {
 /* udev-rules.c */
 struct udev_rules;
 struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names);
-void udev_rules_unref(struct udev_rules *rules);
+struct udev_rules *udev_rules_unref(struct udev_rules *rules);
 int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event, const sigset_t *sigmask);
 void udev_rules_apply_static_dev_perms(struct udev_rules *rules);
 
@@ -109,7 +109,7 @@ int udev_ctrl_get_fd(struct udev_ctrl *uctrl);
 int udev_ctrl_send_set_log_level(struct udev_ctrl *uctrl, int priority, int timeout);
 int udev_ctrl_send_stop_exec_queue(struct udev_ctrl *uctrl, int timeout);
 int udev_ctrl_send_start_exec_queue(struct udev_ctrl *uctrl, int timeout);
-int udev_ctrl_send_reload_rules(struct udev_ctrl *uctrl, int timeout);
+int udev_ctrl_send_reload(struct udev_ctrl *uctrl, int timeout);
 int udev_ctrl_send_ping(struct udev_ctrl *uctrl, int timeout);
 int udev_ctrl_send_exit(struct udev_ctrl *uctrl, int timeout);
 int udev_ctrl_send_set_env(struct udev_ctrl *uctrl, const char *key, int timeout);
@@ -125,7 +125,7 @@ struct udev_ctrl_msg *udev_ctrl_msg_unref(struct udev_ctrl_msg *ctrl_msg);
 int udev_ctrl_get_set_log_level(struct udev_ctrl_msg *ctrl_msg);
 int udev_ctrl_get_stop_exec_queue(struct udev_ctrl_msg *ctrl_msg);
 int udev_ctrl_get_start_exec_queue(struct udev_ctrl_msg *ctrl_msg);
-int udev_ctrl_get_reload_rules(struct udev_ctrl_msg *ctrl_msg);
+int udev_ctrl_get_reload(struct udev_ctrl_msg *ctrl_msg);
 int udev_ctrl_get_ping(struct udev_ctrl_msg *ctrl_msg);
 int udev_ctrl_get_exit(struct udev_ctrl_msg *ctrl_msg);
 const char *udev_ctrl_get_set_env(struct udev_ctrl_msg *ctrl_msg);
index 130a71b3d0db6e9d17e65f5f54eb65a2b9767f45..dd1d5d783fc119c9432d3b042d99555eeec95d0c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2008 Kay Sievers <kay.sievers@vrfy.org>
+ * Copyright (C) 2005-2011 Kay Sievers <kay.sievers@vrfy.org>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -32,9 +32,9 @@ static void print_help(void)
        printf("Usage: udevadm control COMMAND\n"
                "  --exit                   instruct the daemon to cleanup and exit\n"
                "  --log-priority=<level>   set the udev log level for the daemon\n"
-               "  --stop-exec-queue        keep udevd from executing events, queue only\n"
+               "  --stop-exec-queue        do not execute events, queue only\n"
                "  --start-exec-queue       execute events, flush queue\n"
-               "  --reload-rules           reloads the rules files\n"
+               "  --reload                 reload rules and databases\n"
                "  --property=<KEY>=<value> set a global property for all events\n"
                "  --children-max=<N>       maximum number of children\n"
                "  --timeout=<seconds>      maximum time to block for a reply\n"
@@ -52,6 +52,7 @@ static int adm_control(struct udev *udev, int argc, char *argv[])
                { "log-priority", required_argument, NULL, 'l' },
                { "stop-exec-queue", no_argument, NULL, 's' },
                { "start-exec-queue", no_argument, NULL, 'S' },
+               { "reload", no_argument, NULL, 'R' },
                { "reload-rules", no_argument, NULL, 'R' },
                { "property", required_argument, NULL, 'p' },
                { "env", required_argument, NULL, 'p' },
@@ -111,7 +112,7 @@ static int adm_control(struct udev *udev, int argc, char *argv[])
                                rc = 0;
                        break;
                case 'R':
-                       if (udev_ctrl_send_reload_rules(uctrl, timeout) < 0)
+                       if (udev_ctrl_send_reload(uctrl, timeout) < 0)
                                rc = 2;
                        else
                                rc = 0;
index 66043c76d6aedb6fb7021f850e25e8ff7491aaff..253fcd0c8fc6e8ffdb24a191de2b9c521f8b6e5f 100644 (file)
@@ -124,4 +124,5 @@ const struct udevadm_cmd udevadm_test_builtin = {
        .name = "test-builtin",
        .cmd = adm_builtin,
        .help = "test a built-in command",
+       .debug = true,
 };
index 09c22c44b1945f9904c6753bd245d83db23a4cb9..455ce80ca9c69840bd073fcbe5963856d5cf2581 100644 (file)
           </listitem>
         </varlistentry>
         <varlistentry>
-          <term><option>--reload-rules</option></term>
+          <term><option>--reload</option></term>
           <listitem>
-            <para>Signal udevd to reload the rules files.
-            The udev daemon detects changes automatically, this option is
-            usually not needed. Reloading rules does not apply any changes
-            to already existing devices.</para>
+            <para>Signal udevd to reload the rules files and other databases like the kernel
+            module index. Reloading rules and databases does not apply any changes to already
+            existing devices; the new configuration will only be applied to new events.</para>
           </listitem>
         </varlistentry>
         <varlistentry>
index 3a39b6a50ab71709d15ddf39650f8d13787434fa..299f5d3f590224bbe7194f3f61c3a17963f878f1 100644 (file)
@@ -76,7 +76,7 @@ static int fd_signal = -1;
 static int fd_ep = -1;
 static int fd_inotify = -1;
 static bool stop_exec_queue;
-static bool reload_config;
+static bool reload;
 static int children;
 static int children_max;
 static int exec_delay;
@@ -662,9 +662,9 @@ static struct udev_ctrl_connection *handle_ctrl_msg(struct udev_ctrl *uctrl)
                stop_exec_queue = false;
        }
 
-       if (udev_ctrl_get_reload_rules(ctrl_msg) > 0) {
-               info(udev, "udevd message (RELOAD_RULES) received\n");
-               reload_config = true;
+       if (udev_ctrl_get_reload(ctrl_msg) > 0) {
+               info(udev, "udevd message (RELOAD) received\n");
+               reload = true;
        }
 
        str = udev_ctrl_get_set_env(ctrl_msg);
@@ -745,7 +745,7 @@ static int handle_inotify(struct udev *udev)
                                continue;
                        if (strlen(s) != strlen(".rules"))
                                continue;
-                       reload_config = true;
+                       reload = true;
                        continue;
                }
 
@@ -831,7 +831,7 @@ static void handle_signal(struct udev *udev, int signo)
                }
                break;
        case SIGHUP:
-               reload_config = true;
+               reload = true;
                break;
        }
 }
@@ -1658,8 +1658,12 @@ int main(int argc, char *argv[])
                }
 
                /* start new events */
-               if (!udev_list_node_is_empty(&event_list) && !udev_exit && !stop_exec_queue)
-                       event_queue_start(udev);
+               if (!udev_list_node_is_empty(&event_list) && !udev_exit && !stop_exec_queue) {
+                       if (rules == NULL)
+                               rules = udev_rules_new(udev, resolve_names);
+                       if (rules != NULL)
+                               event_queue_start(udev);
+               }
 
                if (is_signal) {
                        struct signalfd_siginfo fdsi;
@@ -1691,19 +1695,11 @@ int main(int argc, char *argv[])
                        ctrl_conn = handle_ctrl_msg(udev_ctrl);
 
                /* rules changed, set by inotify or a HUP signal */
-               if (reload_config) {
-                       struct udev_rules *rules_new;
-
+               if (reload) {
                        worker_kill(udev, 0);
-                       rules_new = udev_rules_new(udev, resolve_names);
-                       if (rules_new != NULL) {
-                               udev_rules_unref(rules);
-                               rules = rules_new;
-                       }
-                       reload_config = 0;
-
+                       rules = udev_rules_unref(rules);
                        udev_builtin_exit(udev);
-                       udev_builtin_init(udev);
+                       reload = 0;
                }
        }