Skip to content

Commit

Permalink
call setsid to avoid unfortunate killing
Browse files Browse the repository at this point in the history
  • Loading branch information
r-c-f committed Sep 7, 2022
1 parent 81d67c9 commit 2a75bc8
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 2a75bc8

Please sign in to comment.