system/corennnnn
修訂 | d4cdd13f6f56f3fe8d8511b609e823925fdd83f9 (tree) |
---|---|
時間 | 2009-05-21 01:52:16 |
作者 | San Mehat <san@goog...> |
Commiter | San Mehat |
init: Clean up dynamic argument handling for services
Signed-off-by: San Mehat <san@google.com>
@@ -193,7 +193,8 @@ void service_start(struct service *svc, const char *dynamic_args) | ||
193 | 193 | } |
194 | 194 | |
195 | 195 | if ((!(svc->flags & SVC_ONESHOT)) && dynamic_args) { |
196 | - ERROR("service '%s' must be one-shot to use dynamic args, disabling\n", svc->args[0]); | |
196 | + ERROR("service '%s' must be one-shot to use dynamic args, disabling\n", | |
197 | + svc->args[0]); | |
197 | 198 | svc->flags |= SVC_DISABLED; |
198 | 199 | return; |
199 | 200 | } |
@@ -258,42 +259,18 @@ void service_start(struct service *svc, const char *dynamic_args) | ||
258 | 259 | execve(svc->args[0], (char**) svc->args, (char**) ENV); |
259 | 260 | else { |
260 | 261 | char *arg_ptrs[SVC_MAXARGS+1]; |
261 | - int arg_idx; | |
262 | + int arg_idx = svc->nargs; | |
262 | 263 | char *tmp = strdup(dynamic_args); |
263 | - char *p = tmp; | |
264 | + char *next = tmp; | |
265 | + char *bword; | |
264 | 266 | |
265 | 267 | /* Copy the static arguments */ |
266 | - for (arg_idx = 0; arg_idx < svc->nargs; arg_idx++) { | |
267 | - arg_ptrs[arg_idx] = svc->args[arg_idx]; | |
268 | - } | |
269 | - | |
270 | - int done = 0; | |
271 | - while(!done) { | |
268 | + memcpy(arg_ptrs, svc->args, (svc->nargs * sizeof(char *))); | |
272 | 269 | |
273 | - if (arg_idx == SVC_MAXARGS) | |
270 | + while((bword = strsep(&next, " "))) { | |
271 | + arg_ptrs[arg_idx++] = bword; | |
272 | + if (arg_idx == SVC_MAXARGS) | |
274 | 273 | break; |
275 | - | |
276 | - /* Advance over any leading whitespace */ | |
277 | - if (*p == ' ') { | |
278 | - for (p; *p != ' '; p++); | |
279 | - p++; | |
280 | - } | |
281 | - /* Locate next argument */ | |
282 | - char *q = p; | |
283 | - while(1) { | |
284 | - if (*q == ' ') { | |
285 | - *q = '\0'; | |
286 | - break; | |
287 | - } else if (*q == '\0') { | |
288 | - done = 1; | |
289 | - break; | |
290 | - } | |
291 | - q++; | |
292 | - } | |
293 | - arg_ptrs[arg_idx++] = p; | |
294 | - | |
295 | - q++; // Advance q to the next string | |
296 | - p = q; | |
297 | 274 | } |
298 | 275 | arg_ptrs[arg_idx] = '\0'; |
299 | 276 | execve(svc->args[0], (char**) arg_ptrs, (char**) ENV); |
@@ -462,7 +439,6 @@ static void msg_start(const char *name) | ||
462 | 439 | svc = service_find_by_name(name); |
463 | 440 | else { |
464 | 441 | tmp = strdup(name); |
465 | - strcpy(tmp, name); | |
466 | 442 | args = strchr(tmp, ':'); |
467 | 443 | *args = '\0'; |
468 | 444 | args++; |
@@ -802,7 +778,7 @@ void handle_keychord(int fd) | ||
802 | 778 | svc = service_find_by_keychord(id); |
803 | 779 | if (svc) { |
804 | 780 | INFO("starting service %s from keychord\n", svc->name); |
805 | - service_start(svc, NULL); | |
781 | + service_start(svc, NULL); | |
806 | 782 | } else { |
807 | 783 | ERROR("service for keychord %d not found\n", id); |
808 | 784 | } |