chiark / gitweb /
[PATCH] handle whole hotplug event with udevd/udev
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>
Tue, 23 Nov 2004 07:01:57 +0000 (08:01 +0100)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 05:37:58 +0000 (22:37 -0700)
If /proc/sys/kernel/hotplug points to /sbin/udevsend we handle the whole
hotplug event with multiplexing /etc/hotplug.d/.

udev.c
udev.h

diff --git a/udev.c b/udev.c
index 8e6d06f1bd0071a3414db5dac712a7d8b218f951..dad64288a9b08f0706807f305a47d7d115df930c 100644 (file)
--- a/udev.c
+++ b/udev.c
@@ -55,6 +55,30 @@ void log_message(int level, const char *format, ...)
 }
 #endif
 
+/* (for now) true if udevsend is the helper */
+static int manage_hotplug_event(void) {
+       char helper[256];
+       int fd;
+       int len;
+
+       fd = open("/proc/sys/kernel/hotplug", O_RDONLY);
+       if (fd < 0)
+               goto exit;
+
+       len = read(fd, helper, 256);
+       close(fd);
+
+       if (len < 0)
+               goto exit;
+       helper[len] = '\0';
+
+       if (strstr(helper, "udevsend"))
+               return 1;
+
+exit:
+       return 0;
+}
+
 static void asmlinkage sig_handler(int signum)
 {
        switch (signum) {
@@ -110,20 +134,20 @@ int main(int argc, char *argv[], char *envp[])
 
        if (!action) {
                dbg("no action");
-               goto exit;
+               goto hotplug;
        }
 
        if (!subsystem) {
                dbg("no subsystem");
-               goto exit;
+               goto hotplug;
        }
 
        if (!devpath) {
                dbg("no devpath");
-               goto exit;
+               goto hotplug;
        }
 
-       /* export logging flag, called scripts may want to do the same as udev */
+       /* export logging flag, as called scripts may want to do the same as udev */
        if (udev_log)
                setenv("UDEV_LOG", "1", 1);
 
@@ -135,14 +159,14 @@ int main(int argc, char *argv[], char *envp[])
                        /* skip blacklisted subsystems */
                        if (udev.type != 'n' && subsystem_expect_no_dev(udev.subsystem)) {
                                dbg("don't care about '%s' devices", udev.subsystem);
-                               goto exit;
+                               goto hotplug;
                        };
 
                        snprintf(path, SYSFS_PATH_MAX, "%s%s", sysfs_path, udev.devpath);
                        class_dev = wait_class_device_open(path);
                        if (class_dev == NULL) {
                                dbg ("open class device failed");
-                               goto exit;
+                               goto hotplug;
                        }
                        dbg("opened class_dev->name='%s'", class_dev->name);
 
@@ -165,7 +189,7 @@ int main(int argc, char *argv[], char *envp[])
                        /* possibly remove a node */
                        dbg("udev remove");
 
-                       /* get node from db, delete it */
+                       /* get node from db, remove db-entry, delete created node */
                        retval = udev_remove_device(&udev);
 
                        /* run dev.d/ scripts if we're not instructed to ignore the event */
@@ -184,7 +208,7 @@ int main(int argc, char *argv[], char *envp[])
                        devices_dev = wait_devices_device_open(path);
                        if (!devices_dev) {
                                dbg("devices device unavailable (probably remove has beaten us)");
-                               goto exit;
+                               goto hotplug;
                        }
                        dbg("devices device opened '%s'", path);
 
@@ -198,6 +222,10 @@ int main(int argc, char *argv[], char *envp[])
                dbg("unhandled");
        }
 
+hotplug:
+       if (manage_hotplug_event())
+               dev_d_execute(&udev, HOTPLUGD_DIR, HOTPLUG_SUFFIX);
+
 exit:
        logging_close();
        return retval;
diff --git a/udev.h b/udev.h
index d9a775ae91ef4dbc90e06c99c2450054ae34176c..e834f1e5b9008fa478fbbc7b062ddb0aed6488a1 100644 (file)
--- a/udev.h
+++ b/udev.h
@@ -44,6 +44,9 @@
 #define DEVD_DIR                       "/etc/dev.d"
 #define DEVD_SUFFIX                    ".dev"
 
+#define HOTPLUGD_DIR                   "/etc/hotplug.d"
+#define HOTPLUG_SUFFIX                 ".hotplug"
+
 struct udevice {
        char devpath[DEVPATH_SIZE];
        char subsystem[SUBSYSTEM_SIZE];