Merge pull request #826 from satherton/fix-fdbmonitor-kill-behavior

FDBMonitor will only kill its entire process group on exit if it star…
This commit is contained in:
Evan Tschannen 2018-11-12 13:18:01 -08:00 committed by GitHub
commit 380e7f97fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 4 deletions

View File

@ -635,13 +635,15 @@ bool argv_equal(const char** a1, const char** a2)
return true;
}
void kill_process(uint64_t id) {
void kill_process(uint64_t id, bool wait = true) {
pid_t pid = id_pid[id];
log_msg(SevInfo, "Killing process %d\n", pid);
kill(pid, SIGTERM);
waitpid(pid, NULL, 0);
if(wait) {
waitpid(pid, NULL, 0);
}
pid_id.erase(pid);
id_pid.erase(id);
@ -1367,8 +1369,19 @@ int main(int argc, char** argv) {
signal(SIGCHLD, SIG_IGN);
sigprocmask(SIG_SETMASK, &normal_mask, NULL);
/* Send SIGHUP to all child processes */
kill(0, SIGHUP);
/* If daemonized, setsid() was called earlier so we can just kill our entire new process group */
if(daemonize) {
kill(0, SIGHUP);
}
else {
/* Otherwise kill each process individually but don't wait on them yet */
auto i = id_pid.begin();
auto iEnd = id_pid.end();
while(i != iEnd) {
// Must advance i before calling kill_process() which erases the entry at i
kill_process((i++)->first, false);
}
}
/* Wait for all child processes (says POSIX.1-2001) */
/* POSIX.1-2001 specifies that if the disposition of SIGCHLD is set to SIG_IGN, then children that terminate do not become zombies and a call to wait()