Plug a leak and expand exec also.
This commit is contained in:
parent
20380d3144
commit
895c4f4149
@ -501,40 +501,42 @@ static void handle_signal(int sig)
|
|||||||
static char *
|
static char *
|
||||||
expand_home(const char *home, const char *path)
|
expand_home(const char *home, const char *path)
|
||||||
{
|
{
|
||||||
char *pat, *p, *nh;
|
char *opath, *ppath, *p, *nh;
|
||||||
size_t len;
|
size_t len;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
|
|
||||||
if (!path || *path != '~')
|
if (!path || *path != '~')
|
||||||
return xstrdup(path);
|
return xstrdup(path);
|
||||||
|
|
||||||
pat = xstrdup(path);
|
opath = ppath = xstrdup(path);
|
||||||
if (pat[1] != '/' && pat[1] != '\0') {
|
if (ppath[1] != '/' && ppath[1] != '\0') {
|
||||||
p = strchr(pat + 1, '/');
|
p = strchr(ppath + 1, '/');
|
||||||
if (p)
|
if (p)
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
pw = getpwnam(pat + 1);
|
pw = getpwnam(ppath + 1);
|
||||||
if (pw) {
|
if (pw) {
|
||||||
home = pw->pw_dir;
|
home = pw->pw_dir;
|
||||||
pat = p;
|
ppath = p;
|
||||||
if (pat)
|
if (ppath)
|
||||||
*pat = '/';
|
*ppath = '/';
|
||||||
} else
|
} else
|
||||||
home = NULL;
|
home = NULL;
|
||||||
} else
|
} else
|
||||||
pat++;
|
ppath++;
|
||||||
|
|
||||||
if (!home) {
|
if (!home) {
|
||||||
free(pat);
|
free(opath);
|
||||||
return xstrdup(path);
|
return xstrdup(path);
|
||||||
}
|
}
|
||||||
if (!pat)
|
if (!ppath) {
|
||||||
|
free(opath);
|
||||||
return xstrdup(home);
|
return xstrdup(home);
|
||||||
|
}
|
||||||
|
|
||||||
len = strlen(pat) + strlen(home) + 1;
|
len = strlen(ppath) + strlen(home) + 1;
|
||||||
nh = xmalloc(len);
|
nh = xmalloc(len);
|
||||||
snprintf(nh, len, "%s%s", home, pat);
|
snprintf(nh, len, "%s%s", home, ppath);
|
||||||
free(pat);
|
free(opath);
|
||||||
return nh;
|
return nh;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -892,6 +894,8 @@ int start_stop_daemon(int argc, char **argv)
|
|||||||
ch_dir = expand_home(home, ch_dir);
|
ch_dir = expand_home(home, ch_dir);
|
||||||
if (ch_root && *ch_root == '~')
|
if (ch_root && *ch_root == '~')
|
||||||
ch_root = expand_home(home, ch_root);
|
ch_root = expand_home(home, ch_root);
|
||||||
|
if (*exec == '~')
|
||||||
|
exec = expand_home(home, exec);
|
||||||
|
|
||||||
/* Validate that the binary exists if we are starting */
|
/* Validate that the binary exists if we are starting */
|
||||||
if (*exec == '/' || *exec == '.') {
|
if (*exec == '/' || *exec == '.') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user