diff options
author | Roy Marples <roy@marples.name> | 2008-11-12 10:55:42 +0000 |
---|---|---|
committer | Roy Marples <roy@marples.name> | 2008-11-12 10:55:42 +0000 |
commit | fe509db6607ded1812f0e2ada4e138eeff458c20 (patch) | |
tree | 98ef9043c7075fb70cc5eb340a650bbc569bb9c6 | |
parent | 937b1b2abf173a75788a88a0d9357958917f4a76 (diff) |
Save a needless malloc when re-creating PATH.
-rw-r--r-- | src/rc/start-stop-daemon.c | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/src/rc/start-stop-daemon.c b/src/rc/start-stop-daemon.c index a3b763d0..e98b1b45 100644 --- a/src/rc/start-stop-daemon.c +++ b/src/rc/start-stop-daemon.c @@ -1131,22 +1131,28 @@ int start_stop_daemon(int argc, char **argv) rc_stringlist_free(env_list); /* For the path, remove the rcscript bin dir from it */ - if ((tmp = xstrdup(getenv("PATH")))) { - len = strlen(tmp); - newpath = np = xmalloc(len); - p = tmp; - while ((token = strsep(&p, ":"))) { - if (strcmp(token, RC_LIBDIR "/bin") == 0 || - strcmp(token, RC_LIBDIR "/sbin") == 0) - continue; - len = strlen(token); - if (np != newpath) - *np++ = ':'; - memcpy(np, token, len); - np += len; - *np = '\0'; + if ((token = getenv("PATH"))) { + len = strlen(token); + newpath = np = xmalloc(len + 1); + while (token && *token) { + p = strchr(token, ':'); + if (p) { + *p++ = '\0'; + while (*p == ':') + p++; + } + if (strcmp(token, RC_LIBDIR "/bin") != 0 && + strcmp(token, RC_LIBDIR "/sbin") != 0) + { + len = strlen(token); + if (np != newpath) + *np++ = ':'; + memcpy(np, token, len); + np += len; + } + token = p; } - free(tmp); + *np = '\0'; unsetenv("PATH"); setenv("PATH", newpath, 1); } |