- pid_t pid;
- char action[] = "ACTION=add";
- char devpath[MAX_PATHLEN];
- char nosleep[] = "UDEV_NO_SLEEP=1";
- char *env[] = { action, devpath, nosleep, NULL };
-
- strcpy(action, "DEVPATH=%s");
- strfieldcat(action, path);
-
- 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;
+ char path[PATH_SIZE];
+
+ /* 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("add '%s'", devpath);
+
+ snprintf(path, sizeof(path), "%s%s", sysfs_path, devpath);
+ path[sizeof(path)-1] = '\0';
+ 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, &class_dev->path[strlen(sysfs_path)], 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(&rules, &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) {
+ if (strncmp(name_loop->name, "socket:", strlen("socket:")) == 0)
+ pass_env_to_socket(&name_loop->name[strlen("socket:")], devpath, "add");
+ else
+ run_program(name_loop->name, udev.subsystem, NULL, 0, NULL, (udev_log_priority >= LOG_INFO));
+ }
+ }
+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;
+ }
+ }