X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=udev.c;h=78090605206f1fab763c4a1dccb21d485967940b;hb=5a73b25fd6673134328443af04afe7bde0060d72;hp=974b9582d0723440f218249263ee82f1c1f5ae3c;hpb=7e89a569cc4db0c1482662dc4df5f60df7aef3ff;p=elogind.git diff --git a/udev.c b/udev.c index 974b9582d..780906052 100644 --- a/udev.c +++ b/udev.c @@ -27,10 +27,12 @@ #include #include #include +#include #include "libsysfs/sysfs/libsysfs.h" #include "udev.h" #include "udev_lib.h" +#include "udev_sysfs.h" #include "udev_version.h" #include "logging.h" #include "namedev.h" @@ -58,40 +60,24 @@ void log_message(int level, const char *format, ...) } #endif -asmlinkage static void sig_handler(int signum) +static void asmlinkage sig_handler(int signum) { switch (signum) { case SIGALRM: gotalarm = 1; - info("error: timeout reached, event probably not handled correctly"); break; case SIGINT: case SIGTERM: - udevdb_exit(); exit(20 + signum); - default: - dbg("unhandled signal %d", signum); } } -static char *subsystem_blacklist[] = { - "scsi_host", - "scsi_device", - "usb_host", - "pci_bus", - "pcmcia_socket", - "" -}; - int main(int argc, char *argv[], char *envp[]) { - main_argv = argv; - main_envp = envp; struct sigaction act; - char *action; - char *devpath = ""; - char *subsystem = ""; - int i; + struct sysfs_class_device *class_dev; + struct udevice udev; + char path[SYSFS_PATH_MAX]; int retval = -EINVAL; enum { ADD, @@ -101,14 +87,20 @@ int main(int argc, char *argv[], char *envp[]) dbg("version %s", UDEV_VERSION); - init_logging("udev"); + main_argv = argv; + main_envp = envp; + + logging_init("udev"); udev_init_config(); if (strstr(argv[0], "udevstart")) { act_type = UDEVSTART; } else { - action = get_action(); + const char *action = get_action(); + const char *devpath = get_devpath(); + const char *subsystem = get_subsystem(main_argv[1]); + if (!action) { dbg("no action?"); goto exit; @@ -118,11 +110,10 @@ int main(int argc, char *argv[], char *envp[]) } else if (strcmp(action, "remove") == 0) { act_type = REMOVE; } else { - dbg("unknown action '%s'", action); + dbg("no action '%s' for us", action); goto exit; } - devpath = get_devpath(); if (!devpath) { dbg("no devpath?"); goto exit; @@ -135,28 +126,26 @@ int main(int argc, char *argv[], char *envp[]) goto exit; } - subsystem = get_subsystem(main_argv[1]); if (!subsystem) { - dbg("no subsystem?"); + dbg("no subsystem"); goto exit; } + udev_set_values(&udev, devpath, subsystem); + /* skip blacklisted subsystems */ - i = 0; - while (subsystem_blacklist[i][0] != '\0') { - if (strcmp(subsystem, subsystem_blacklist[i]) == 0) { - dbg("don't care about '%s' devices", subsystem); - goto exit; - } - i++; - } + if (udev.type != 'n' && subsystem_expect_no_dev(subsystem)) { + dbg("don't care about '%s' devices", subsystem); + goto exit; + }; + } /* set signal handlers */ - act.sa_handler = sig_handler; - + act.sa_handler = (void (*) (int))sig_handler; sigemptyset (&act.sa_mask); - /* alarm must interrupt syscalls*/ + act.sa_flags = 0; + /* alarm must not restart syscalls*/ sigaction(SIGALRM, &act, NULL); sigaction(SIGINT, &act, NULL); sigaction(SIGTERM, &act, NULL); @@ -172,21 +161,44 @@ int main(int argc, char *argv[], char *envp[]) case UDEVSTART: dbg("udevstart"); namedev_init(); - udev_sleep = 0; retval = udev_start(); break; case ADD: dbg("udev add"); + + /* open the device */ + snprintf(path, SYSFS_PATH_MAX, "%s%s", sysfs_path, udev.devpath); + class_dev = sysfs_open_class_device_path(path); + if (class_dev == NULL) { + dbg ("sysfs_open_class_device_path failed"); + break; + } + dbg("opened class_dev->name='%s'", class_dev->name); + + /* init rules */ namedev_init(); - retval = udev_add_device(devpath, subsystem, NOFAKE); + + /* name, create node, store in db */ + retval = udev_add_device(&udev, class_dev); + + /* run scripts */ + dev_d_execute(&udev); + + sysfs_close_class_device(class_dev); break; case REMOVE: dbg("udev remove"); - retval = udev_remove_device(devpath, subsystem); + + /* get node from db, delete it*/ + retval = udev_remove_device(&udev); + + /* run scripts */ + dev_d_execute(&udev); } udevdb_exit(); exit: + logging_close(); return retval; }