- /* trigger timout to interrupt blocking syscalls */
- alarm(ALARM_TIMEOUT);
-
- /* initialize udev database */
- if (udevdb_init(UDEVDB_DEFAULT) != 0)
- info("error: unable to initialize database, continuing without database");
-
- switch(act_type) {
- case UDEVSTART:
- dbg("udevstart");
- namedev_init();
- udev_sleep = 0;
- retval = udev_start();
- break;
- case ADD:
- dbg("udev add");
- namedev_init();
- retval = udev_add_device(devpath, subsystem, NOFAKE);
- break;
- case REMOVE:
- dbg("udev remove");
- retval = udev_remove_device(devpath, subsystem);
+ dev = sysfs_device_get(devpath);
+ if (dev == NULL) {
+ info("unable to open '%s'", devpath);
+ goto fail;
+ }
+
+ udev = udev_device_init();
+ if (udev == NULL)
+ goto fail;
+
+ /* override built-in sysfs device */
+ udev->dev = dev;
+ strlcpy(udev->action, action, sizeof(udev->action));
+
+ /* get dev_t from environment, which is needed for "remove" to work, "add" works also from sysfs */
+ maj = getenv("MAJOR");
+ min = getenv("MINOR");
+ if (maj != NULL && min != NULL)
+ udev->devt = makedev(atoi(maj), atoi(min));
+ else
+ udev->devt = udev_device_get_devt(udev);
+
+ retval = udev_device_event(&rules, udev);
+
+ if (retval == 0 && !udev->ignore_device && udev_run) {
+ struct name_entry *name_loop;
+
+ dbg("executing run list");
+ list_for_each_entry(name_loop, &udev->run_list, node) {
+ if (strncmp(name_loop->name, "socket:", strlen("socket:")) == 0)
+ pass_env_to_socket(&name_loop->name[strlen("socket:")], devpath, action);
+ else {
+ char program[PATH_SIZE];
+
+ strlcpy(program, name_loop->name, sizeof(program));
+ udev_rules_apply_format(udev, program, sizeof(program));
+ run_program(program, udev->dev->subsystem, NULL, 0, NULL, (udev_log_priority >= LOG_INFO));
+ }
+ }