diff options
author | Roy Marples <roy@marples.name> | 2008-09-22 10:45:01 +0000 |
---|---|---|
committer | Roy Marples <roy@marples.name> | 2008-09-22 10:45:01 +0000 |
commit | 554d2fea19274c2c4c7483b2b93d78b6ae9cbde9 (patch) | |
tree | cfc0f7d20b2f7087eb3db269639a368d33044ec8 | |
parent | a63303971a8909550b1895f273a04b682baef3ae (diff) |
Allow interpreted daemons to detect interperter options.
-rw-r--r-- | src/rc/start-stop-daemon.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/rc/start-stop-daemon.c b/src/rc/start-stop-daemon.c index 045bad12..7e850abe 100644 --- a/src/rc/start-stop-daemon.c +++ b/src/rc/start-stop-daemon.c @@ -866,19 +866,27 @@ int start_stop_daemon(int argc, char **argv) fgets(line, sizeof(line), fp); fclose(fp); if (line[0] == '#' && line[1] == '!') { + p = line + 2; + /* Strip leading spaces */ + while (*p == ' ') + p++; /* Remove the trailing newline */ - len = strlen(line) - 1; - if (line[len] == '\n') - line[len] = '\0'; - strncpy(exec_file, line + 2, sizeof(exec_file)); + len = strlen(p) - 1; + if (p[len] == '\n') + p[len] = '\0'; + token = strsep(&p, " "); + strncpy(exec_file, token, sizeof(exec_file)); + token = strsep(&p, " "); opt = 0; for (nav = argv; *nav; nav++) opt++; - nav = xmalloc(sizeof(char *) * (opt + 2)); + nav = xmalloc(sizeof(char *) * (opt + token ? 3 : 2)); nav[0] = exec_file; + if (token) + nav[1] = token; for (i = 0; i < opt; i++) - nav[i + 1] = argv[i]; - nav[i + 1] = '\0'; + nav[i + token ? 2 : 1] = argv[i]; + nav[i + token ? 2 : 1] = '\0'; argv = nav; exec = exec_file; } |