Save a needless malloc when re-creating PATH.
This commit is contained in:
parent
937b1b2abf
commit
fe509db660
@ -1131,22 +1131,28 @@ int start_stop_daemon(int argc, char **argv)
|
|||||||
rc_stringlist_free(env_list);
|
rc_stringlist_free(env_list);
|
||||||
|
|
||||||
/* For the path, remove the rcscript bin dir from it */
|
/* For the path, remove the rcscript bin dir from it */
|
||||||
if ((tmp = xstrdup(getenv("PATH")))) {
|
if ((token = getenv("PATH"))) {
|
||||||
len = strlen(tmp);
|
len = strlen(token);
|
||||||
newpath = np = xmalloc(len);
|
newpath = np = xmalloc(len + 1);
|
||||||
p = tmp;
|
while (token && *token) {
|
||||||
while ((token = strsep(&p, ":"))) {
|
p = strchr(token, ':');
|
||||||
if (strcmp(token, RC_LIBDIR "/bin") == 0 ||
|
if (p) {
|
||||||
strcmp(token, RC_LIBDIR "/sbin") == 0)
|
*p++ = '\0';
|
||||||
continue;
|
while (*p == ':')
|
||||||
len = strlen(token);
|
p++;
|
||||||
if (np != newpath)
|
}
|
||||||
*np++ = ':';
|
if (strcmp(token, RC_LIBDIR "/bin") != 0 &&
|
||||||
memcpy(np, token, len);
|
strcmp(token, RC_LIBDIR "/sbin") != 0)
|
||||||
np += len;
|
{
|
||||||
*np = '\0';
|
len = strlen(token);
|
||||||
|
if (np != newpath)
|
||||||
|
*np++ = ':';
|
||||||
|
memcpy(np, token, len);
|
||||||
|
np += len;
|
||||||
|
}
|
||||||
|
token = p;
|
||||||
}
|
}
|
||||||
free(tmp);
|
*np = '\0';
|
||||||
unsetenv("PATH");
|
unsetenv("PATH");
|
||||||
setenv("PATH", newpath, 1);
|
setenv("PATH", newpath, 1);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user