- 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 udevice udev;
+ struct sysfs_class_device *class_dev;
+ const char *devpath;
+
+ devpath = &path[strlen(sysfs_path)];
+
+ /* clear and set environment for next event */
+ clearenv();
+ setenv("ACTION", "add", 1);
+ setenv("DEVPATH", devpath, 1);
+ setenv("SUBSYSTEM", subsystem, 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);
+ dbg("exec: '%s' (%s)\n", devpath, path);
+
+ class_dev = sysfs_open_class_device_path(path);
+ if (class_dev == NULL) {
+ dbg("sysfs_open_class_device_path failed");
+ return -1;
+ }
+
+ udev_init_device(&udev, devpath, subsystem, "add");
+ udev.devt = get_devt(class_dev);
+ if (!udev.devt && udev.type != DEV_NET) {
+ dbg("sysfs_open_class_device_path failed");
+ return -1;
+ }
+ udev_rules_get_name(&udev, class_dev);
+ if (udev.ignore_device) {
+ dbg("device event will be ignored");
+ goto exit;
+ }
+ if (udev.name[0] == '\0') {
+ dbg("device node creation supressed");
+ goto run;
+ }
+
+ udev_add_device(&udev, class_dev);
+ if (udev.devname[0] != '\0')
+ setenv("DEVNAME", udev.devname, 1);
+run:
+ if (udev_run && !list_empty(&udev.run_list)) {
+ struct name_entry *name_loop;
+
+ dbg("executing run list");
+ list_for_each_entry(name_loop, &udev.run_list, node)
+ execute_program(name_loop->name, udev.subsystem, NULL, 0, NULL);
+ }
+exit:
+ sysfs_close_class_device(class_dev);
+ udev_cleanup_device(&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, loop_device->subsys);
+ 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, loop_device->subsys);
+ 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, loop_device->subsys);
+ list_del(&loop_device->node);
+ free(loop_device);