]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
[PATCH] fix problems using scsi_id with udevstart
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>
Thu, 7 Oct 2004 06:20:39 +0000 (23:20 -0700)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 04:37:03 +0000 (21:37 -0700)
when udevstart was running we didn't set the environment and the
subsystem argument for the callouts the dev.d/ scripts.

Here is a fix, that sets that with every udevstart iteration, corrects
argv[0] to be the basename() only not the whole path  and adds a test
for invoking callouts without arguments.

namedev.c
test/udev-test.pl
udevstart.c

index fe7dddaf55bafa0138562a731d67d4738c310906..3843d028693c305b4bf0e15ae93f14e4b3589815 100644 (file)
--- a/namedev.c
+++ b/namedev.c
@@ -412,7 +412,7 @@ static void fix_kernel_name(struct udevice *udev)
        }
 }
 
-static int execute_program(char *path, char *value, int len)
+static int execute_program(const char *path, char *value, int len)
 {
        int retval;
        int count;
@@ -421,12 +421,12 @@ static int execute_program(char *path, char *value, int len)
        pid_t pid;
        char *pos;
        char arg[PROGRAM_SIZE];
-       char *argv[sizeof(arg) / 2];
+       char *argv[(PROGRAM_SIZE / 2) + 1];
        int i;
 
+       strfieldcpy(arg, path);
        i = 0;
        if (strchr(path, ' ')) {
-               strfieldcpy(arg, path);
                pos = arg;
                while (pos != NULL) {
                        if (pos[0] == '\'') {
@@ -441,8 +441,19 @@ static int execute_program(char *path, char *value, int len)
                        dbg("arg[%i] '%s'", i, argv[i]);
                        i++;
                }
+               argv[i] =  NULL;
+               dbg("execute '%s' with parsed arguments", arg);
+       } else {
+               argv[0] = arg;
+               argv[1] = main_argv[1];
+               argv[2] = NULL;
+               dbg("execute '%s' with subsystem '%s' argument", arg, argv[1]);
        }
-       argv[i] =  NULL;
+
+       /* set basename() only */
+       pos = strrchr(argv[0], '/');
+       if (pos != NULL)
+               argv[0] = &pos[1];
 
        retval = pipe(fds);
        if (retval != 0) {
@@ -456,13 +467,7 @@ static int execute_program(char *path, char *value, int len)
                /* child */
                /* dup2 write side of pipe to STDOUT */
                dup2(fds[1], STDOUT_FILENO);
-               if (argv[0] !=  NULL) {
-                       dbg("execute '%s' with given arguments", argv[0]);
-                       retval = execv(argv[0], argv);
-               } else {
-                       dbg("execute '%s' with main argument", path);
-                       retval = execv(path, main_argv);
-               }
+               retval = execv(arg, argv);
 
                info(FIELD_PROGRAM " execution of '%s' failed", path);
                exit(1);
index 590b551dfe7fbf036bf0a52a934bd4d2512324f9..9e4e192c51230f3465cd8e59bea774d7df2a2065 100644 (file)
@@ -253,6 +253,15 @@ BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special--*", NAME="%c
 BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special-device-", NAME="%c-3-%n"
 BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special-devic", NAME="%c-4-%n"
 BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special-*", NAME="%c-%n"
+EOF
+       },
+       {
+               desc            => "program result substitution (no argument should be subsystem)",
+               subsys          => "block",
+               devpath         => "/block/sda/sda3",
+               exp_name        => "subsys_block" ,
+               conf            => <<EOF
+BUS="scsi", PROGRAM="/bin/echo", RESULT="block", NAME="subsys_block"
 EOF
        },
        {
index ba63745620cbeec1e5d3ac5744a45a30d4bacb62..cabafb0abc76689064131e41d87ebdcb90276d19 100644 (file)
@@ -86,6 +86,21 @@ static char *first_list[] = {
        NULL,
 };
 
+static void add_device(char *path, char *subsys, int fake)
+{
+       char *argv[3];
+
+       /* fake argument vector and environment for callouts and dev.d/ */
+       argv[0] = "udev";
+       argv[1] = subsys;
+       argv[2] = NULL;
+
+       main_argv = argv;
+       setenv("DEVPATH", path, 1);
+       setenv("ACTION", "add", 1);
+       udev_add_device(path, subsys, fake);
+}
+
 static void exec_list(struct list_head *device_list)
 {
        struct device *loop_device;
@@ -96,7 +111,7 @@ static void exec_list(struct list_head *device_list)
        list_for_each_entry_safe(loop_device, tmp_device, device_list, list) {
                for (i=0; first_list[i] != NULL; i++) {
                        if (strncmp(loop_device->path, first_list[i], strlen(first_list[i])) == 0) {
-                               udev_add_device(loop_device->path, loop_device->subsys, NOFAKE);
+                               add_device(loop_device->path, loop_device->subsys, NOFAKE);
                                list_del(&loop_device->list);
                                free(loop_device);
                                break;
@@ -116,14 +131,14 @@ static void exec_list(struct list_head *device_list)
                if (found)
                        continue;
 
-               udev_add_device(loop_device->path, loop_device->subsys, NOFAKE);
+               add_device(loop_device->path, loop_device->subsys, NOFAKE);
                list_del(&loop_device->list);
                free(loop_device);
        }
 
        /* handle the rest of the devices left over, if any */
        list_for_each_entry_safe(loop_device, tmp_device, device_list, list) {
-               udev_add_device(loop_device->path, loop_device->subsys, NOFAKE);
+               add_device(loop_device->path, loop_device->subsys, NOFAKE);
                list_del(&loop_device->list);
                free(loop_device);
        }