aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Timber <mieabby@gmail.com>2020-09-27 23:23:12 +0930
committerDavid Timber <mieabby@gmail.com>2020-09-27 23:23:12 +0930
commit39c944e091e315831e92e89d784c0bcd1d345749 (patch)
treed48a8ee31379f7176ebe8373af2ef238d01de587
parent86038b950f0aaddca7108e903568159414a8d64a (diff)
Proone ignores SIGTERM as `killall -TERM` kills
both process instantly. Use `killall -INT` to signal normal exit.
-rw-r--r--src/proone.c51
1 files changed, 29 insertions, 22 deletions
diff --git a/src/proone.c b/src/proone.c
index 5e8173e..180da8f 100644
--- a/src/proone.c
+++ b/src/proone.c
@@ -1453,25 +1453,24 @@ int main (const int argc, const char **args) {
prne_dbgpf("* Child: %d\n", prne_g.child_pid);
- do {
- prne_assert(sigwait(&ss_all, &caught_signal) == 0);
-
- switch (caught_signal) {
- case SIGINT:
- case SIGTERM:
- // Exit requested. Notify the child and wait for it to exit.
- loop = false;
- sigprocmask(SIG_UNBLOCK, &ss_exit, NULL);
- kill(prne_g.child_pid, SIGTERM);
- continue;
- case SIGCHLD:
- prne_assert(waitpid(prne_g.child_pid, &status, WNOHANG) == prne_g.child_pid);
- break;
- case SIGPIPE:
- prne_dbgpf("** Parent received SIGPIPE. WHAT???\n");
- continue;
- }
- } while (false);
+WAIT_LOOP:
+ prne_assert(sigwait(&ss_all, &caught_signal) == 0);
+
+ switch (caught_signal) {
+ case SIGINT:
+ // Exit requested. Notify the child and wait for it to exit.
+ loop = false;
+ sigprocmask(SIG_UNBLOCK, &ss_exit, NULL);
+ kill(prne_g.child_pid, SIGTERM);
+ goto WAIT_LOOP;
+ case SIGCHLD:
+ prne_assert(waitpid(
+ prne_g.child_pid,
+ &status,
+ 0) == prne_g.child_pid);
+ break;
+ default: goto WAIT_LOOP;
+ }
if (prne_s_g != NULL) {
has_ny_bin = strlen(prne_s_g->ny_bin_path) > 0;
@@ -1482,10 +1481,15 @@ int main (const int argc, const char **args) {
}
if (WIFEXITED(status)) {
- prne_dbgpf("* Child process %d exited with code %d!\n", prne_g.child_pid, WEXITSTATUS(status));
+ prne_dbgpf(
+ "* Child process %d exited with code %d!\n",
+ prne_g.child_pid,
+ WEXITSTATUS(status));
if (WEXITSTATUS(status) == 0) {
if (has_ny_bin) {
- prne_dbgpf("* Detected new bin. Attempting to exec()\n");
+ prne_dbgpf(
+ "* Detected new bin. "
+ "Attempting to exec()\n");
run_ny_bin();
// run_ny_bin() returns if fails
}
@@ -1495,7 +1499,10 @@ int main (const int argc, const char **args) {
}
}
else if (WIFSIGNALED(status)) {
- prne_dbgpf("** Child process %d received signal %d!\n", prne_g.child_pid, WTERMSIG(status));
+ prne_dbgpf(
+ "** Child process %d received signal %d!\n",
+ prne_g.child_pid,
+ WTERMSIG(status));
}
if (has_ny_bin) {