From 2a75bc88b6a0da84e52be56d610274624220c1e9 Mon Sep 17 00:00:00 2001 From: Ryan Farley Date: Wed, 7 Sep 2022 05:43:08 -0500 Subject: [PATCH] call setsid to avoid unfortunate killing --- src/main.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main.c b/src/main.c index 979fe0c..8d02704 100644 --- a/src/main.c +++ b/src/main.c @@ -163,6 +163,15 @@ int main(int argc, char **argv) /* and drop said privileges */ osDropPriv(); + /* we want to be the leader of a single process group, to make + * cleanup easier */ + if (getpgid(getpid()) != getpid()) { + if (setsid() != getpid()) { + fprintf(stderr, "could not create session\n"); + return 1; + } + } + /* we default to name being hostname, so get it*/ if (gethostname(hostname, _POSIX_HOST_NAME_MAX - 1) == -1) { perror("gethostname");