From d07557b9b6ba72f50c6b80ea06cecac61cf9eeb1 Mon Sep 17 00:00:00 2001 From: "kay.sievers@vrfy.org" Date: Tue, 23 Nov 2004 08:01:57 +0100 Subject: [PATCH] [PATCH] handle whole hotplug event with udevd/udev If /proc/sys/kernel/hotplug points to /sbin/udevsend we handle the whole hotplug event with multiplexing /etc/hotplug.d/. --- udev.c | 44 ++++++++++++++++++++++++++++++++++++-------- udev.h | 3 +++ 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/udev.c b/udev.c index 8e6d06f1..dad64288 100644 --- 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 d9a775ae..e834f1e5 100644 --- 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]; -- 2.39.5