X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=dev_d.c;h=817355af60397c4c4f221a793c860d0b0f859ecd;hb=cc0e9bfc350e6a8b3fff79a9a0f2a97afa9b3825;hp=64c254424867a63eefb5986a99acf029cc19e73e;hpb=e920fed3499aa1445657b62499a11348faa3b24e;p=elogind.git diff --git a/dev_d.c b/dev_d.c index 64c254424..817355af6 100644 --- a/dev_d.c +++ b/dev_d.c @@ -29,25 +29,20 @@ #include "udev.h" #include "udev_lib.h" -#include "udevdb.h" #include "logging.h" -#define DEVD_DIR "/etc/dev.d/" -#define DEVD_SUFFIX ".dev" - -static int run_program(char *name) +static int run_program(const char *filename, void *data) { pid_t pid; int fd; - char *argv[3]; + struct udevice *udev = data; - dbg("running %s", name); + dbg("running %s", filename); pid = fork(); switch (pid) { case 0: /* child */ - udevdb_exit(); /* close udevdb */ fd = open("/dev/null", O_RDWR); if ( fd >= 0) { dup2(fd, STDOUT_FILENO); @@ -56,11 +51,7 @@ static int run_program(char *name) } close(fd); - argv[0] = name; - argv[1] = main_argv[1]; - argv[2] = NULL; - - execv(name, argv); + execl(filename, filename, udev->subsystem, NULL); dbg("exec of child failed"); _exit(1); case -1: @@ -80,7 +71,7 @@ static int run_program(char *name) * subsystem/ * default/ */ -void dev_d_execute(struct udevice *udev) +void dev_d_execute(struct udevice *udev, const char *basedir, const char *suffix) { char dirname[PATH_MAX]; char devname[NAME_SIZE]; @@ -90,37 +81,34 @@ void dev_d_execute(struct udevice *udev) if (udev_dev_d == 0) return; - /* 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 '/' */ + /* chop the device name up into pieces based on '/' */ temp = strchr(devname, '/'); while (temp != NULL) { temp[0] = '\0'; - strcpy(dirname, DEVD_DIR); - strfieldcat(dirname, devname); - call_foreach_file(run_program, dirname, DEVD_SUFFIX); + snprintf(dirname, PATH_MAX, "%s/%s", basedir, devname); + dirname[PATH_MAX-1] = '\0'; + call_foreach_file(run_program, dirname, suffix, udev); temp[0] = '/'; ++temp; temp = strchr(temp, '/'); } - strcpy(dirname, DEVD_DIR); - strfieldcat(dirname, udev->name); - call_foreach_file(run_program, dirname, DEVD_SUFFIX); + if (udev->name[0] != '\0') { + snprintf(dirname, PATH_MAX, "%s/%s", basedir, udev->name); + dirname[PATH_MAX-1] = '\0'; + call_foreach_file(run_program, dirname, suffix, udev); + } - strcpy(dirname, DEVD_DIR); - strfieldcat(dirname, udev->subsystem); - call_foreach_file(run_program, dirname, DEVD_SUFFIX); + if (udev->subsystem[0] != '\0') { + snprintf(dirname, PATH_MAX, "%s/%s", basedir, udev->subsystem); + dirname[PATH_MAX-1] = '\0'; + call_foreach_file(run_program, dirname, suffix, udev); + } - strcpy(dirname, DEVD_DIR "default"); - call_foreach_file(run_program, dirname, DEVD_SUFFIX); + snprintf(dirname, PATH_MAX, "%s/default", basedir); + dirname[PATH_MAX-1] = '\0'; + call_foreach_file(run_program, dirname, suffix, udev); }