X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=namedev.c;h=24b9bc01ac2258f24fb85c67fb1a8c2fce5844cd;hp=7c8761088f304036b4a3b3994fa3e06e082ed4da;hb=04a81cac0aab2ab6a54ddc661dd57be7d5b1595a;hpb=cb08e0f2531f910fcd46a24b2fa0eb8049165b02;ds=sidebyside diff --git a/namedev.c b/namedev.c index 7c8761088..24b9bc01a 100644 --- a/namedev.c +++ b/namedev.c @@ -45,6 +45,7 @@ #define TYPE_TOPOLOGY "TOPOLOGY" #define TYPE_REPLACE "REPLACE" #define TYPE_CALLOUT "CALLOUT" +#define CALLOUT_MAXARG 8 static LIST_HEAD(config_device_list); @@ -438,12 +439,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 +492,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 +512,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 +554,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) {