diff options
author | kay.sievers@vrfy.org <kay.sievers@vrfy.org> | 2004-11-23 08:01:57 +0100 |
---|---|---|
committer | Greg KH <gregkh@suse.de> | 2005-04-26 22:37:58 -0700 |
commit | d07557b9b6ba72f50c6b80ea06cecac61cf9eeb1 (patch) | |
tree | 19c22eaaf18a81863a31764e633220eb12293316 | |
parent | c449b25e3f998efe8f5988632126fb468ee55fc5 (diff) |
[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/.
-rw-r--r-- | udev.c | 44 | ||||
-rw-r--r-- | udev.h | 3 |
2 files changed, 39 insertions, 8 deletions
@@ -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; @@ -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]; |