We should match on the correct args for stopping daemons when pidfiles
are not being used.
This commit is contained in:
parent
9d9f17aa52
commit
53e2bec385
@ -368,6 +368,7 @@ static int run_stop_schedule(const char *exec, const char *const *argv,
|
|||||||
long nloops;
|
long nloops;
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
pid_t pid = 0;
|
pid_t pid = 0;
|
||||||
|
const char *const *p;
|
||||||
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
if (exec)
|
if (exec)
|
||||||
@ -376,8 +377,15 @@ static int run_stop_schedule(const char *exec, const char *const *argv,
|
|||||||
einfo("Will stop PID in pidfile `%s'", pidfile);
|
einfo("Will stop PID in pidfile `%s'", pidfile);
|
||||||
if (uid)
|
if (uid)
|
||||||
einfo("Will stop processes owned by UID %d", uid);
|
einfo("Will stop processes owned by UID %d", uid);
|
||||||
if (argv && *argv)
|
if (argv && *argv) {
|
||||||
einfo("Will stop processes of `%s'", *argv);
|
einfon("Will stop processes of `");
|
||||||
|
for (p = argv; p && *p; p++) {
|
||||||
|
if (p != argv)
|
||||||
|
printf(" ");
|
||||||
|
printf("%s", *p);
|
||||||
|
}
|
||||||
|
printf("'\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pidfile) {
|
if (pidfile) {
|
||||||
@ -840,13 +848,13 @@ int start_stop_daemon(int argc, char **argv)
|
|||||||
exec = name;
|
exec = name;
|
||||||
if (name && start)
|
if (name && start)
|
||||||
*argv = name;
|
*argv = name;
|
||||||
} else if (name && (start || **argv))
|
} else if (name)
|
||||||
*--argv = name;
|
*--argv = name;
|
||||||
else
|
else if (exec)
|
||||||
*--argv = exec;
|
*--argv = exec;
|
||||||
|
|
||||||
if (stop || sig) {
|
if (stop || sig) {
|
||||||
if ( !*argv && !pidfile && !name && !uid)
|
if (!*argv && !pidfile && !name && !uid)
|
||||||
eerrorx("%s: --stop needs --exec, --pidfile,"
|
eerrorx("%s: --stop needs --exec, --pidfile,"
|
||||||
" --name or --user", applet);
|
" --name or --user", applet);
|
||||||
if (background)
|
if (background)
|
||||||
@ -868,45 +876,12 @@ int start_stop_daemon(int argc, char **argv)
|
|||||||
eerrorx("%s: --stdout and --stderr are only relevant"
|
eerrorx("%s: --stdout and --stderr are only relevant"
|
||||||
" with --background", applet);
|
" with --background", applet);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stop || sig) {
|
|
||||||
if (!sig)
|
|
||||||
sig = SIGTERM;
|
|
||||||
if (!stop)
|
|
||||||
oknodo = true;
|
|
||||||
if (!TAILQ_FIRST(&schedule)) {
|
|
||||||
if (test || oknodo)
|
|
||||||
parse_schedule("0", sig);
|
|
||||||
else
|
|
||||||
parse_schedule(NULL, sig);
|
|
||||||
}
|
|
||||||
i = run_stop_schedule(exec, (const char *const *)argv,
|
|
||||||
pidfile, uid, quiet, verbose, test);
|
|
||||||
|
|
||||||
if (i < 0)
|
|
||||||
/* We failed to stop something */
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
if (test || oknodo)
|
|
||||||
return i > 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
||||||
|
|
||||||
/* Even if we have not actually killed anything, we should
|
|
||||||
* remove information about it as it may have unexpectedly
|
|
||||||
* crashed out. We should also return success as the end
|
|
||||||
* result would be the same. */
|
|
||||||
if (pidfile && exists(pidfile))
|
|
||||||
unlink(pidfile);
|
|
||||||
if (svcname)
|
|
||||||
rc_service_daemon_set(svcname, exec,
|
|
||||||
(const char *const *)argv,
|
|
||||||
pidfile, false);
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Expand ~ */
|
/* Expand ~ */
|
||||||
if (ch_dir && *ch_dir == '~')
|
if (ch_dir && *ch_dir == '~')
|
||||||
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) {
|
||||||
if (*exec == '~')
|
if (*exec == '~')
|
||||||
exec = expand_home(home, exec);
|
exec = expand_home(home, exec);
|
||||||
|
|
||||||
@ -914,25 +889,31 @@ int start_stop_daemon(int argc, char **argv)
|
|||||||
if (*exec == '/' || *exec == '.') {
|
if (*exec == '/' || *exec == '.') {
|
||||||
/* Full or relative path */
|
/* Full or relative path */
|
||||||
if (ch_root)
|
if (ch_root)
|
||||||
snprintf(exec_file, sizeof(exec_file), "%s/%s", ch_root, exec);
|
snprintf(exec_file, sizeof(exec_file),
|
||||||
|
"%s/%s", ch_root, exec);
|
||||||
else
|
else
|
||||||
snprintf(exec_file, sizeof(exec_file), "%s", exec);
|
snprintf(exec_file, sizeof(exec_file),
|
||||||
|
"%s", exec);
|
||||||
} else {
|
} else {
|
||||||
/* Something in $PATH */
|
/* Something in $PATH */
|
||||||
p = tmp = xstrdup(getenv("PATH"));
|
p = tmp = xstrdup(getenv("PATH"));
|
||||||
*exec_file = '\0';
|
*exec_file = '\0';
|
||||||
while ((token = strsep(&p, ":"))) {
|
while ((token = strsep(&p, ":"))) {
|
||||||
if (ch_root)
|
if (ch_root)
|
||||||
snprintf(exec_file, sizeof(exec_file), "%s/%s/%s", ch_root, token, exec);
|
snprintf(exec_file, sizeof(exec_file),
|
||||||
|
"%s/%s/%s",
|
||||||
|
ch_root, token, exec);
|
||||||
else
|
else
|
||||||
snprintf(exec_file, sizeof(exec_file), "%s/%s", token, exec);
|
snprintf(exec_file, sizeof(exec_file),
|
||||||
|
"%s/%s", token, exec);
|
||||||
if (exists(exec_file))
|
if (exists(exec_file))
|
||||||
break;
|
break;
|
||||||
*exec_file = '\0';
|
*exec_file = '\0';
|
||||||
}
|
}
|
||||||
free(tmp);
|
free(tmp);
|
||||||
}
|
}
|
||||||
if (!exists(exec_file)) {
|
}
|
||||||
|
if (start && !exists(exec_file)) {
|
||||||
eerror("%s: %s does not exist", applet,
|
eerror("%s: %s does not exist", applet,
|
||||||
*exec_file ? exec_file : exec);
|
*exec_file ? exec_file : exec);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@ -971,9 +952,41 @@ int start_stop_daemon(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
margv = nav ? nav : argv;
|
margv = nav ? nav : argv;
|
||||||
|
|
||||||
|
if (stop || sig) {
|
||||||
|
if (!sig)
|
||||||
|
sig = SIGTERM;
|
||||||
|
if (!stop)
|
||||||
|
oknodo = true;
|
||||||
|
if (!TAILQ_FIRST(&schedule)) {
|
||||||
|
if (test || oknodo)
|
||||||
|
parse_schedule("0", sig);
|
||||||
|
else
|
||||||
|
parse_schedule(NULL, sig);
|
||||||
|
}
|
||||||
|
i = run_stop_schedule(exec, (const char *const *)margv,
|
||||||
|
pidfile, uid, quiet, verbose, test);
|
||||||
|
|
||||||
|
if (i < 0)
|
||||||
|
/* We failed to stop something */
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
if (test || oknodo)
|
||||||
|
return i > 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
|
|
||||||
|
/* Even if we have not actually killed anything, we should
|
||||||
|
* remove information about it as it may have unexpectedly
|
||||||
|
* crashed out. We should also return success as the end
|
||||||
|
* result would be the same. */
|
||||||
|
if (pidfile && exists(pidfile))
|
||||||
|
unlink(pidfile);
|
||||||
|
if (svcname)
|
||||||
|
rc_service_daemon_set(svcname, exec,
|
||||||
|
(const char *const *)argv,
|
||||||
|
pidfile, false);
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
if (pidfile)
|
if (pidfile)
|
||||||
pid = get_pid(pidfile, true);
|
pid = get_pid(pidfile, true);
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user