diff options
-rw-r--r-- | dev_d.c | 37 | ||||
-rw-r--r-- | udev.c | 10 | ||||
-rw-r--r-- | udev.h | 3 | ||||
-rw-r--r-- | udev_add.c | 39 | ||||
-rw-r--r-- | udev_remove.c | 20 | ||||
-rw-r--r-- | udevdb.c | 3 | ||||
-rw-r--r-- | udevstart.c | 10 | ||||
-rw-r--r-- | udevtest.c | 17 |
8 files changed, 75 insertions, 64 deletions
@@ -62,7 +62,7 @@ static int run_program(char *name) execv(name, argv); dbg("exec of child failed"); - exit(1); + _exit(1); case -1: dbg("fork of child failed"); break; @@ -80,42 +80,35 @@ static int run_program(char *name) * subsystem/ * default/ */ -void dev_d_send(struct udevice *udev) +void dev_d_execute(struct udevice *udev) { - char dirname[256]; - char env_devname[NAME_SIZE]; - char *devname; + char dirname[PATH_MAX]; + char devname[NAME_SIZE]; char *temp; + /* skip if UDEV_NO_DEVD is set */ if (udev_dev_d == 0) return; - memset(env_devname, 0x00, sizeof(env_devname)); - if (udev->type == 'b' || udev->type == 'c') { - strfieldcpy(env_devname, udev_root); - strfieldcat(env_devname, udev->name); - } else if (udev->type == 'n') { - strfieldcpy(env_devname, udev->name); - setenv("DEVPATH", udev->devpath, 1); - } - setenv("DEVNAME", env_devname, 1); - dbg("DEVNAME='%s'", env_devname); - - devname = strdup(udev->name); - if (!devname) { - dbg("out of memory"); + /* skip if udev did nothing, like unchanged netif or no "dev" file */ + if (udev->devname[0] == '\0') return; - } + + /* add the node name or the netif name to the environment */ + setenv("DEVNAME", udev->devname, 1); + dbg("DEVNAME='%s'", udev->devname); + + strfieldcpy(devname, udev->name); /* Chop the device name up into pieces based on '/' */ temp = strchr(devname, '/'); while (temp != NULL) { - *temp = 0x00; + temp[0] = '\0'; strcpy(dirname, DEVD_DIR); strfieldcat(dirname, devname); call_foreach_file(run_program, dirname, DEVD_SUFFIX); - *temp = '/'; + temp[0] = '/'; ++temp; temp = strchr(temp, '/'); } @@ -210,10 +210,20 @@ int main(int argc, char *argv[], char *envp[]) /* name, create node, store in db */ retval = udev_add_device(&udev, class_dev); + + /* run scripts */ + dev_d_execute(&udev); + + sysfs_close_class_device(class_dev); break; case REMOVE: dbg("udev remove"); + + /* get node from db, delete it*/ retval = udev_remove_device(&udev); + + /* run scripts */ + dev_d_execute(&udev); } udevdb_exit(); @@ -66,6 +66,7 @@ struct udevice { char program_result[NAME_SIZE]; char kernel_number[NAME_SIZE]; char kernel_name[NAME_SIZE]; + char devname[NAME_SIZE]; int test_run; }; @@ -74,7 +75,7 @@ extern int udev_remove_device(struct udevice *udev); extern void udev_init_config(void); extern int udev_start(void); extern int parse_get_pair(char **orig_string, char **left, char **right); -extern void dev_d_send(struct udevice *udev); +extern void dev_d_execute(struct udevice *udev); extern char **main_argv; extern char **main_envp; diff --git a/udev_add.c b/udev_add.c index d07120de62..809a33cedb 100644 --- a/udev_add.c +++ b/udev_add.c @@ -355,7 +355,7 @@ int udev_add_device(struct udevice *udev, struct sysfs_class_device *class_dev) retval = get_major_minor(class_dev, udev); if (retval != 0) { dbg("no dev-file found, do nothing"); - goto close; + return 0; } } @@ -365,45 +365,44 @@ int udev_add_device(struct udevice *udev, struct sysfs_class_device *class_dev) dbg("adding name='%s'", udev->name); selinux_init(); - switch (udev->type) { - case 'b': - case 'c': + + if (udev->type == 'b' || udev->type == 'c') { retval = create_node(udev); if (retval != 0) goto exit; - if ((!udev->test_run) && (udevdb_add_dev(udev) != 0)) - dbg("udevdb_add_dev failed, but we are going to try " - "to create the node anyway. But remove might not " - "work properly for this device."); - dev_d_send(udev); - break; + if (udevdb_add_dev(udev) != 0) + dbg("udevdb_add_dev failed, but we create the node anyway, " + "remove might not work for custom names"); - case 'n': + /* use full path to the environment */ + snprintf(udev->devname, NAME_SIZE-1, "%s%s", udev_root, udev->name); + + } else if (udev->type == 'n') { + /* look if we want to change the name of the netif */ if (strcmp(udev->name, udev->kernel_name) != 0) { retval = rename_net_if(udev); if (retval != 0) goto exit; - /* netif's are keyed with the configured name, cause - * the original kernel name sleeps with the fishes + + /* we've changed the name, now fake the devpath, + * cause original kernel name sleeps with the fishes + * and we don't get any event from the kernel now */ pos = strrchr(udev->devpath, '/'); if (pos != NULL) { pos[1] = '\0'; strfieldcat(udev->devpath, udev->name); + setenv("DEVPATH", udev->devpath, 1); } - } - if ((!udev->test_run) && (udevdb_add_dev(udev) != 0)) - dbg("udevdb_add_dev failed"); - dev_d_send(udev); - break; + /* use netif name for the environment */ + strfieldcpy(udev->devname, udev->name); + } } exit: selinux_restore(); -close: - sysfs_close_class_device(class_dev); return retval; } diff --git a/udev_remove.c b/udev_remove.c index d97a2411f4..0dcec731ea 100644 --- a/udev_remove.c +++ b/udev_remove.c @@ -36,7 +36,7 @@ #include "namedev.h" #include "udevdb.h" -static int delete_path(char *path) +static int delete_path(const char *path) { char *pos; int retval; @@ -168,14 +168,15 @@ static int delete_node(struct udevice *dev) int udev_remove_device(struct udevice *udev) { struct udevice db_dev; - char *temp; + const char *temp; int retval; - memset(&db_dev, 0x00, sizeof(struct udevice)); + if (udev->type != 'b' && udev->type != 'c') + return 0; retval = udevdb_get_dev(udev->devpath, &db_dev); if (retval == 0) { - /* get stored values in our device */ + /* copy over the stored values to our device */ memcpy(udev, &db_dev, UDEVICE_DB_LEN); } else { /* fall back to kernel name */ @@ -185,15 +186,12 @@ int udev_remove_device(struct udevice *udev) strfieldcpy(udev->name, &temp[1]); dbg("'%s' not found in database, falling back on default name", udev->name); } - dbg("remove name='%s'", udev->name); - dev_d_send(udev); + dbg("remove name='%s'", udev->name); udevdb_delete_dev(udev->devpath); - if (udev->type == 'b' || udev->type == 'c') - retval = delete_node(udev); - else - retval = 0; + /* use full path to the environment */ + snprintf(udev->devname, NAME_SIZE-1, "%s%s", udev_root, udev->name); - return retval; + return delete_node(udev); } @@ -49,6 +49,9 @@ int udevdb_add_dev(struct udevice *udev) TDB_DATA key, data; char keystr[SYSFS_PATH_MAX]; + if (udev->test_run) + return 0; + if (udevdb == NULL) return -1; diff --git a/udevstart.c b/udevstart.c index c4ec0f7b7a..fd490f0791 100644 --- a/udevstart.c +++ b/udevstart.c @@ -103,7 +103,7 @@ static int add_device(char *devpath, char *subsystem) setenv("DEVPATH", devpath, 1); setenv("ACTION", "add", 1); - snprintf(path, SYSFS_PATH_MAX, "%s%s", sysfs_path, devpath); + snprintf(path, SYSFS_PATH_MAX-1, "%s%s", sysfs_path, devpath); class_dev = sysfs_open_class_device_path(path); if (class_dev == NULL) { dbg ("sysfs_open_class_device_path failed"); @@ -111,8 +111,14 @@ static int add_device(char *devpath, char *subsystem) } udev_set_values(&udev, devpath, subsystem); + udev_add_device(&udev, class_dev); - return udev_add_device(&udev, class_dev); + /* run scripts */ + dev_d_execute(&udev); + + sysfs_close_class_device(class_dev); + + return 0; } static void exec_list(struct list_head *device_list) diff --git a/udevtest.c b/udevtest.c index fa1629af25..f2b0c98edb 100644 --- a/udevtest.c +++ b/udevtest.c @@ -69,12 +69,9 @@ int main(int argc, char *argv[], char *envp[]) if (argv[1] == NULL) { info("udevinfo expects the DEVPATH of the sysfs device as a argument"); - goto exit; + return 1; } - /* initialize our configuration */ - udev_init_config(); - /* remove sysfs_path if given */ if (strncmp(argv[1], sysfs_path, strlen(sysfs_path)) == 0) devpath = argv[1] + strlen(sysfs_path); @@ -93,9 +90,12 @@ int main(int argc, char *argv[], char *envp[]) /* we only care about class devices and block stuff */ if (!strstr(devpath, "class") && !strstr(devpath, "block")) { dbg("not a block or class device"); - goto exit; + return 2; } + /* initialize our configuration */ + udev_init_config(); + /* initialize the naming deamon */ namedev_init(); @@ -104,7 +104,6 @@ int main(int argc, char *argv[], char *envp[]) /* fill in values and test_run flag*/ udev_set_values(&udev, devpath, subsystem); - udev.test_run = 1; /* open the device */ snprintf(path, SYSFS_PATH_MAX, "%s%s", sysfs_path, udev.devpath); @@ -114,9 +113,11 @@ int main(int argc, char *argv[], char *envp[]) else dbg("opened class_dev->name='%s'", class_dev->name); - /* simulate node creation with fake flag */ + /* simulate node creation with test flag */ + udev.test_run = 1; udev_add_device(&udev, class_dev); -exit: + sysfs_close_class_device(class_dev); + return 0; } |