+static int add_device(const char *devpath)
+{
+ 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();
+ 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) {
+ 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:")], udev->dev->devpath, "add");
+ 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));
+ }
+ }
+ }
+
+exit:
+ udev_device_cleanup(udev);
+ return 0;
+}
+