From fe509db6607ded1812f0e2ada4e138eeff458c20 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Wed, 12 Nov 2008 10:55:42 +0000 Subject: Save a needless malloc when re-creating PATH. --- src/rc/start-stop-daemon.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'src') 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); } -- cgit v1.2.3