diff options
author | San Mehat <san@google.com> | 2009-05-20 09:52:16 -0700 |
---|---|---|
committer | San Mehat <san@google.com> | 2009-05-20 09:52:16 -0700 |
commit | d4cdd13f6f56f3fe8d8511b609e823925fdd83f9 (patch) | |
tree | 3659cacc0cac979525c269f32707d6be6f77b7b2 | |
parent | e6be870641d6db12493342c53344d68f464cc0a8 (diff) | |
download | system_core-d4cdd13f6f56f3fe8d8511b609e823925fdd83f9.zip system_core-d4cdd13f6f56f3fe8d8511b609e823925fdd83f9.tar.gz system_core-d4cdd13f6f56f3fe8d8511b609e823925fdd83f9.tar.bz2 |
init: Clean up dynamic argument handling for services
Signed-off-by: San Mehat <san@google.com>
-rw-r--r-- | init/init.c | 44 |
1 files changed, 10 insertions, 34 deletions
diff --git a/init/init.c b/init/init.c index b350569..0c1ad3f 100644 --- a/init/init.c +++ b/init/init.c @@ -193,7 +193,8 @@ void service_start(struct service *svc, const char *dynamic_args) } if ((!(svc->flags & SVC_ONESHOT)) && dynamic_args) { - ERROR("service '%s' must be one-shot to use dynamic args, disabling\n", svc->args[0]); + ERROR("service '%s' must be one-shot to use dynamic args, disabling\n", + svc->args[0]); svc->flags |= SVC_DISABLED; return; } @@ -258,42 +259,18 @@ void service_start(struct service *svc, const char *dynamic_args) execve(svc->args[0], (char**) svc->args, (char**) ENV); else { char *arg_ptrs[SVC_MAXARGS+1]; - int arg_idx; + int arg_idx = svc->nargs; char *tmp = strdup(dynamic_args); - char *p = tmp; + char *next = tmp; + char *bword; /* Copy the static arguments */ - for (arg_idx = 0; arg_idx < svc->nargs; arg_idx++) { - arg_ptrs[arg_idx] = svc->args[arg_idx]; - } - - int done = 0; - while(!done) { + memcpy(arg_ptrs, svc->args, (svc->nargs * sizeof(char *))); - if (arg_idx == SVC_MAXARGS) + while((bword = strsep(&next, " "))) { + arg_ptrs[arg_idx++] = bword; + if (arg_idx == SVC_MAXARGS) break; - - /* Advance over any leading whitespace */ - if (*p == ' ') { - for (p; *p != ' '; p++); - p++; - } - /* Locate next argument */ - char *q = p; - while(1) { - if (*q == ' ') { - *q = '\0'; - break; - } else if (*q == '\0') { - done = 1; - break; - } - q++; - } - arg_ptrs[arg_idx++] = p; - - q++; // Advance q to the next string - p = q; } arg_ptrs[arg_idx] = '\0'; execve(svc->args[0], (char**) arg_ptrs, (char**) ENV); @@ -462,7 +439,6 @@ static void msg_start(const char *name) svc = service_find_by_name(name); else { tmp = strdup(name); - strcpy(tmp, name); args = strchr(tmp, ':'); *args = '\0'; args++; @@ -802,7 +778,7 @@ void handle_keychord(int fd) svc = service_find_by_keychord(id); if (svc) { INFO("starting service %s from keychord\n", svc->name); - service_start(svc, NULL); + service_start(svc, NULL); } else { ERROR("service for keychord %d not found\n", id); } |