[systemd-commits] 2 commits - src/udev

Kay Sievers kay at kemper.freedesktop.org
Wed Aug 8 07:33:18 PDT 2012


 src/udev/udev-builtin-kmod.c |   23 +++++++----------------
 src/udev/udev-builtin.c      |   14 +++++++++++++-
 src/udev/udev-rules.c        |    5 ++++-
 src/udev/udevd.c             |    5 +++--
 4 files changed, 27 insertions(+), 20 deletions(-)

New commits:
commit 7781e063e8e9d3e92e4e158e1588b885808cda24
Author: Kay Sievers <kay at vrfy.org>
Date:   Wed Aug 8 16:27:11 2012 +0200

    udev: re-initialize builtins in the daemon process, not in the worker

diff --git a/src/udev/udev-builtin-kmod.c b/src/udev/udev-builtin-kmod.c
index 87a81bf..baf8c8c 100644
--- a/src/udev/udev-builtin-kmod.c
+++ b/src/udev/udev-builtin-kmod.c
@@ -1,7 +1,7 @@
 /*
  * load kernel modules
  *
- * Copyright (C) 2011 Kay Sievers <kay.sievers at vrfy.org>
+ * Copyright (C) 2011-21012 Kay Sievers <kay.sievers at vrfy.org>
  * Copyright (C) 2011 ProFUSION embedded systems
  *
  * This program is free software: you can redistribute it and/or modify
@@ -39,6 +39,8 @@ static int load_module(struct udev *udev, const char *alias)
         struct kmod_list *l;
         int err;
 
+        assert(ctx);
+
         err = kmod_module_new_from_lookup(ctx, alias, &list);
         if (err < 0)
                 return err;
@@ -70,22 +72,11 @@ static void udev_kmod_log(void *data, int priority, const char *file, int line,
         udev_main_log(data, priority, file, line, fn, format, args);
 }
 
-/* needs to re-instantiate the context after a reload */
 static int builtin_kmod(struct udev_device *dev, int argc, char *argv[], bool test)
 {
         struct udev *udev = udev_device_get_udev(dev);
         int i;
 
-        if (!ctx) {
-                ctx = kmod_new(NULL, NULL);
-                if (!ctx)
-                        return -ENOMEM;
-
-                log_debug("load module index\n");
-                kmod_set_log_fn(ctx, udev_kmod_log, udev);
-                kmod_load_resources(ctx);
-        }
-
         if (argc < 3 || strcmp(argv[1], "load")) {
                 log_error("expect: %s load <module>\n", argv[0]);
                 return EXIT_FAILURE;
@@ -99,7 +90,7 @@ static int builtin_kmod(struct udev_device *dev, int argc, char *argv[], bool te
         return EXIT_SUCCESS;
 }
 
-/* called at udev startup */
+/* called at udev startup and reload */
 static int builtin_kmod_init(struct udev *udev)
 {
         if (ctx)
@@ -126,9 +117,9 @@ static void builtin_kmod_exit(struct udev *udev)
 static bool builtin_kmod_validate(struct udev *udev)
 {
         log_debug("validate module index\n");
-        if (kmod_validate_resources(ctx) != KMOD_RESOURCES_OK)
-                return true;
-        return false;
+        if (!ctx)
+                return false;
+        return (kmod_validate_resources(ctx) != KMOD_RESOURCES_OK);
 }
 
 const struct udev_builtin udev_builtin_kmod = {
diff --git a/src/udev/udev-builtin.c b/src/udev/udev-builtin.c
index 6509f58..7d89f22 100644
--- a/src/udev/udev-builtin.c
+++ b/src/udev/udev-builtin.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007-2009 Kay Sievers <kay.sievers at vrfy.org>
+ * Copyright (C) 2007-2012 Kay Sievers <kay.sievers at 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
@@ -25,6 +25,8 @@
 
 #include "udev.h"
 
+static bool initialized;
+
 static const struct udev_builtin *builtins[] = {
         [UDEV_BUILTIN_BLKID] = &udev_builtin_blkid,
         [UDEV_BUILTIN_FIRMWARE] = &udev_builtin_firmware,
@@ -44,6 +46,9 @@ int udev_builtin_init(struct udev *udev)
         unsigned int i;
         int err = 0;
 
+        if (initialized)
+                return 0;
+
         for (i = 0; i < ELEMENTSOF(builtins); i++) {
                 if (builtins[i]->init) {
                         err = builtins[i]->init(udev);
@@ -51,6 +56,8 @@ int udev_builtin_init(struct udev *udev)
                                 break;
                 }
         }
+
+        initialized = true;
         return err;
 }
 
@@ -58,9 +65,14 @@ void udev_builtin_exit(struct udev *udev)
 {
         unsigned int i;
 
+        if (!initialized)
+                return;
+
         for (i = 0; i < ELEMENTSOF(builtins); i++)
                 if (builtins[i]->exit)
                         builtins[i]->exit(udev);
+
+        initialized = false;
 }
 
 bool udev_builtin_validate(struct udev *udev)
diff --git a/src/udev/udevd.c b/src/udev/udevd.c
index b78c18f..23351ae 100644
--- a/src/udev/udevd.c
+++ b/src/udev/udevd.c
@@ -1107,7 +1107,7 @@ int main(int argc, char *argv[])
                 case 'D':
                         debug = true;
                         log_set_max_level(LOG_DEBUG);
-                        udev_set_log_priority(udev, LOG_INFO);
+                        udev_set_log_priority(udev, LOG_DEBUG);
                         break;
                 case 'N':
                         if (strcmp (optarg, "early") == 0) {
@@ -1486,7 +1486,7 @@ int main(int argc, char *argv[])
                         worker_kill(udev);
                         rules = udev_rules_unref(rules);
                         udev_builtin_exit(udev);
-                        reload = 0;
+                        reload = false;
                 }
 
                 /* event has finished */
@@ -1506,6 +1506,7 @@ int main(int argc, char *argv[])
 
                 /* start new events */
                 if (!udev_list_node_is_empty(&event_list) && !udev_exit && !stop_exec_queue) {
+                        udev_builtin_init(udev);
                         if (rules == NULL)
                                 rules = udev_rules_new(udev, resolve_names);
                         if (rules != NULL)

commit 3b8c1cb01f1b752543738779668d9841ecbca0d3
Author: Kay Sievers <kay at vrfy.org>
Date:   Wed Aug 8 14:45:16 2012 +0200

    udev: initialize rules dir timestamps when reading rules
    
    On Wed, Aug 8, 2012 at 11:48 AM, Michael Schroeder <mls at suse.de> wrote:
    > if rules are installed in the first 3 seconds after the udev start,
    > the stamps will all be zero, so the [first] call to check_rules_timestamp()
    > will just copy the current mtime [and not cause a rules re-load].

diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c
index d3b33e4..1860455 100644
--- a/src/udev/udev-rules.c
+++ b/src/udev/udev-rules.c
@@ -1770,12 +1770,15 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names)
                 return NULL;
         }
         strv_uniq(rules->dirs);
+
+        rules->dirs_ts_usec = calloc(strv_length(rules->dirs), sizeof(long long));
+        udev_rules_check_timestamp(rules);
+
         r = conf_files_list_strv(&files, ".rules", (const char **)rules->dirs);
         if (r < 0) {
                 log_error("failed to enumerate rules files: %s\n", strerror(-r));
                 return NULL;
         }
-        rules->dirs_ts_usec = calloc(strv_length(rules->dirs), sizeof(long long));
 
         /*
          * The offset value in the rules strct is limited; add all



More information about the systemd-commits mailing list