chiark / gitweb /
[PATCH] only build klibc_fixups.c if we are actually using klibc.
[elogind.git] / namedev.c
index 41480d50c02c0553061c5ece7ce55aedfc86f897..3b19aaf9099c8de0a848adb557d17e097f415f18 100644 (file)
--- a/namedev.c
+++ b/namedev.c
 #include "udev_version.h"
 #include "namedev.h"
 #include "libsysfs/libsysfs.h"
+#include "klibc_fixups.h"
 
 #define TYPE_LABEL     "LABEL"
 #define TYPE_NUMBER    "NUMBER"
 #define TYPE_TOPOLOGY  "TOPOLOGY"
 #define TYPE_REPLACE   "REPLACE"
 #define TYPE_CALLOUT   "CALLOUT"
+#define CALLOUT_MAXARG 8
 
 static LIST_HEAD(config_device_list);
 
@@ -286,7 +288,7 @@ static int namedev_init_config(void)
 
                        /* ID="id" */
                        temp2 = strsep(&temp, ",");
-                       retval = get_value("id", &temp, &temp3);
+                       retval = get_value("ID", &temp, &temp3);
                        if (retval)
                                break;
                        strfieldcpy(dev.id, temp3);
@@ -314,7 +316,7 @@ static int namedev_init_config(void)
 
                        /* PLACE="place" */
                        temp2 = strsep(&temp, ",");
-                       retval = get_value("place", &temp, &temp3);
+                       retval = get_value("PLACE", &temp, &temp3);
                        if (retval)
                                break;
                        strfieldcpy(dev.place, temp3);
@@ -353,18 +355,18 @@ static int namedev_init_config(void)
                        /* number type */
                        dev.type = CALLOUT;
 
-                       /* PROGRAM="executable" */
-                       retval = get_value("PROGRAM", &temp, &temp3);
+                       /* BUS="bus" */
+                       retval = get_value("BUS", &temp, &temp3);
                        if (retval)
                                break;
-                       strfieldcpy(dev.exec_program, temp3);
+                       strfieldcpy(dev.bus, temp3);
 
-                       /* BUS="bus" */
+                       /* PROGRAM="executable" */
                        temp2 = strsep(&temp, ",");
-                       retval = get_value("BUS", &temp, &temp3);
+                       retval = get_value("PROGRAM", &temp, &temp3);
                        if (retval)
                                break;
-                       strfieldcpy(dev.bus, temp3);
+                       strfieldcpy(dev.exec_program, temp3);
 
                        /* ID="id" */
                        temp2 = strsep(&temp, ",");
@@ -438,12 +440,24 @@ static int namedev_init_permissions(void)
 
                /* parse the line */
                temp2 = strsep(&temp, ":");
+               if (!temp2) {
+                       dbg("cannot parse line: %s", line);
+                       continue;
+               }
                strncpy(dev.name, temp2, sizeof(dev.name));
 
                temp2 = strsep(&temp, ":");
+               if (!temp2) {
+                       dbg("cannot parse line: %s", line);
+                       continue;
+               }
                strncpy(dev.owner, temp2, sizeof(dev.owner));
 
                temp2 = strsep(&temp, ":");
+               if (!temp2) {
+                       dbg("cannot parse line: %s", line);
+                       continue;
+               }
                strncpy(dev.group, temp2, sizeof(dev.owner));
 
                dev.mode = strtol(temp, NULL, 8);
@@ -479,6 +493,9 @@ static int exec_callout(struct config_device *dev, char *value, int len)
        pid_t pid;
        int value_set = 0;
        char buffer[256];
+       char *arg;
+       char *args[CALLOUT_MAXARG];
+       int i;
 
        dbg("callout to '%s'", dev->exec_program);
        retval = pipe(fds);
@@ -496,7 +513,22 @@ static int exec_callout(struct config_device *dev, char *value, int len)
                /* child */
                close(STDOUT_FILENO);
                dup(fds[1]);    /* dup write side of pipe to STDOUT */
-               retval = execve(dev->exec_program, main_argv, main_envp);
+               if (strchr(dev->exec_program, ' ')) {
+                       /* callout with arguments */
+                       arg = dev->exec_program;
+                       for (i=0; i < CALLOUT_MAXARG-1; i++) {
+                               args[i] = strsep(&arg, " ");
+                               if (args[i] == NULL)
+                                       break;
+                       }
+                       if (args[i]) {
+                               dbg("to many args - %d", i);
+                               args[i] = NULL;
+                       }
+                       retval = execve(args[0], args, main_envp);
+               } else {
+                       retval = execve(dev->exec_program, main_argv, main_envp);
+               }
                if (retval != 0) {
                        dbg("child execve failed");
                        exit(1);
@@ -523,6 +555,7 @@ static int exec_callout(struct config_device *dev, char *value, int len)
                                strncpy(value, buffer, len);
                        }
                }
+               dbg("callout returned '%s'", value);
                close(fds[0]);
                res = wait(&status);
                if (res < 0) {