execv(name, argv);
dbg("exec of child failed");
- exit(1);
+ _exit(1);
case -1:
dbg("fork of child failed");
break;
* 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, '/');
}
/* 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();
char program_result[NAME_SIZE];
char kernel_number[NAME_SIZE];
char kernel_name[NAME_SIZE];
+ char devname[NAME_SIZE];
int test_run;
};
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;
retval = get_major_minor(class_dev, udev);
if (retval != 0) {
dbg("no dev-file found, do nothing");
- goto close;
+ return 0;
}
}
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;
}
#include "namedev.h"
#include "udevdb.h"
-static int delete_path(char *path)
+static int delete_path(const char *path)
{
char *pos;
int retval;
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 */
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);
}
TDB_DATA key, data;
char keystr[SYSFS_PATH_MAX];
+ if (udev->test_run)
+ return 0;
+
if (udevdb == NULL)
return -1;
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");
}
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)
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);
/* 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();
/* 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);
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;
}