• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/corennnnn


Commit MetaInfo

修訂d4cdd13f6f56f3fe8d8511b609e823925fdd83f9 (tree)
時間2009-05-21 01:52:16
作者San Mehat <san@goog...>
CommiterSan Mehat

Log Message

init: Clean up dynamic argument handling for services

Signed-off-by: San Mehat <san@google.com>

Change Summary

差異

--- a/init/init.c
+++ b/init/init.c
@@ -193,7 +193,8 @@ void service_start(struct service *svc, const char *dynamic_args)
193193 }
194194
195195 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]);
197198 svc->flags |= SVC_DISABLED;
198199 return;
199200 }
@@ -258,42 +259,18 @@ void service_start(struct service *svc, const char *dynamic_args)
258259 execve(svc->args[0], (char**) svc->args, (char**) ENV);
259260 else {
260261 char *arg_ptrs[SVC_MAXARGS+1];
261- int arg_idx;
262+ int arg_idx = svc->nargs;
262263 char *tmp = strdup(dynamic_args);
263- char *p = tmp;
264+ char *next = tmp;
265+ char *bword;
264266
265267 /* 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 *)));
272269
273- if (arg_idx == SVC_MAXARGS)
270+ while((bword = strsep(&next, " "))) {
271+ arg_ptrs[arg_idx++] = bword;
272+ if (arg_idx == SVC_MAXARGS)
274273 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;
297274 }
298275 arg_ptrs[arg_idx] = '\0';
299276 execve(svc->args[0], (char**) arg_ptrs, (char**) ENV);
@@ -462,7 +439,6 @@ static void msg_start(const char *name)
462439 svc = service_find_by_name(name);
463440 else {
464441 tmp = strdup(name);
465- strcpy(tmp, name);
466442 args = strchr(tmp, ':');
467443 *args = '\0';
468444 args++;
@@ -802,7 +778,7 @@ void handle_keychord(int fd)
802778 svc = service_find_by_keychord(id);
803779 if (svc) {
804780 INFO("starting service %s from keychord\n", svc->name);
805- service_start(svc, NULL);
781+ service_start(svc, NULL);
806782 } else {
807783 ERROR("service for keychord %d not found\n", id);
808784 }