+/* list of devices that we should run first due to any one of a number of reasons */
+static char *first_list[] = {
+ "/class/mem",
+ "/class/tty",
+ NULL,
+};
+
+static int add_device(const char *devpath, const char *subsystem)
+{
+ 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, 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(&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;
+}
+