From 554d2fea19274c2c4c7483b2b93d78b6ae9cbde9 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Mon, 22 Sep 2008 10:45:01 +0000 Subject: Allow interpreted daemons to detect interperter options. --- src/rc/start-stop-daemon.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src') 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; } -- cgit v1.2.3