- pid_t pid;
- char action[] = "ACTION=add";
- char devpath[MAX_PATHLEN];
- char nosleep[] = "UDEV_NO_SLEEP=1";
- char *env[] = { action, devpath, nosleep, NULL };
-
- snprintf(devpath, MAX_PATHLEN, "DEVPATH=%s", path);
- devpath[MAX_PATHLEN-1] = '\0';
-
- pid = fork();
- switch (pid) {
- case 0:
- /* child */
- execle(UDEV_BIN, "udev", subsystem, NULL, env);
- dbg("exec of child failed");
- exit(1);
- break;
- case -1:
- dbg("fork of child failed");
- break;
- default:
- wait(NULL);
+ struct sysfs_device *dev;
+ struct udevice *udev;
+ int retval = 0;
+
+ /* clear and set environment for next event */
+ clearenv();
+ setenv("ACTION", "add", 1);
+ setenv("UDEV_START", "1", 1);
+ if (udev_log_str)
+ setenv("UDEV_LOG", udev_log_str, 1);
+ if (udev_run_str)
+ setenv("UDEV_RUN", udev_run_str, 1);
+
+ dev = sysfs_device_get(devpath);
+ if (dev == NULL)
+ return -1;
+
+ udev = udev_device_init(NULL);
+ if (udev == NULL)
+ return -1;
+
+ /* override built-in sysfs device */
+ udev->dev = dev;
+ strcpy(udev->action, "add");
+
+ if (strcmp(udev->dev->subsystem, "net") != 0) {
+ udev->devt = udev_device_get_devt(udev);
+ if (major(udev->devt) == 0)
+ return -1;
+ }
+
+ dbg("add '%s'", udev->dev->devpath);
+ setenv("DEVPATH", udev->dev->devpath, 1);
+ setenv("SUBSYSTEM", udev->dev->subsystem, 1);
+
+ udev_rules_get_name(&rules, udev);
+ if (udev->ignore_device) {
+ dbg("device event will be ignored");
+ goto exit;
+ }
+ if (udev->name[0] != '\0')
+ retval = udev_device_event(&rules, udev);
+ else
+ info("device node creation supressed");
+
+ if (retval == 0 && udev_run)
+ udev_rules_run(udev);
+
+exit:
+ udev_device_cleanup(udev);
+ return 0;
+}
+
+static void exec_list(struct list_head *device_list)
+{
+ struct device *loop_device;
+ struct device *tmp_device;
+ int i;
+
+ /* handle the "first" type devices first */
+ list_for_each_entry_safe(loop_device, tmp_device, device_list, node) {
+ for (i = 0; first_list[i] != NULL; i++) {
+ if (strncmp(loop_device->path, first_list[i], strlen(first_list[i])) == 0) {
+ add_device(loop_device->path);
+ list_del(&loop_device->node);
+ free(loop_device);
+ break;
+ }
+ }
+ }
+
+ /* handle the devices we are allowed to, excluding the "last" type devices */
+ list_for_each_entry_safe(loop_device, tmp_device, device_list, node) {
+ int found = 0;
+ for (i = 0; last_list[i] != NULL; i++) {
+ if (strncmp(loop_device->path, last_list[i], strlen(last_list[i])) == 0) {
+ found = 1;
+ break;
+ }
+ }
+ if (found)
+ continue;
+
+ add_device(loop_device->path);
+ list_del(&loop_device->node);
+ free(loop_device);
+ }
+
+ /* handle the rest of the devices left over, if any */
+ list_for_each_entry_safe(loop_device, tmp_device, device_list, node) {
+ add_device(loop_device->path);
+ list_del(&loop_device->node);
+ free(loop_device);