aboutsummaryrefslogtreecommitdiff
path: root/src/libthread/daemonize.c
diff options
context:
space:
mode:
authorPetter Rodhelind <petter.rodhelind@gmail.com>2021-02-18 20:21:24 +0100
committerPetter Rodhelind <petter.rodhelind@gmail.com>2021-02-18 20:21:24 +0100
commit181d56ee64da53279bb6ecf49c24ab54cfb7193f (patch)
treefc6c8736bb97790a257c5514998c583ffce7c41c /src/libthread/daemonize.c
parent94c521bf102a74aec7e1a5c3a9ef5eaa968d4e14 (diff)
parent90971376a5e8620fc62579aa1b3be26245ec8c06 (diff)
downloadplan9port-master.tar.gz
plan9port-master.tar.bz2
plan9port-master.zip
Merge remote-tracking branch 'upstream/master'HEADmaster
Diffstat (limited to 'src/libthread/daemonize.c')
-rw-r--r--src/libthread/daemonize.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/libthread/daemonize.c b/src/libthread/daemonize.c
index 387d1527..29929068 100644
--- a/src/libthread/daemonize.c
+++ b/src/libthread/daemonize.c
@@ -8,7 +8,7 @@
#undef wait
static int sigpid;
-static int threadpassfd;
+static int threadpassfd = -1;
static int gotsigchld;
static void
@@ -101,6 +101,13 @@ _threadsetupdaemonize(void)
sigpid = 1;
+ /*
+ * We've been told this program is likely to background itself.
+ * Put it in its own process group so that we don't get a SIGHUP
+ * when the parent exits.
+ */
+ setpgrp();
+
if(pipe(p) < 0)
sysfatal("passer pipe: %r");
@@ -163,9 +170,9 @@ _threadsetupdaemonize(void)
void
_threaddaemonize(void)
{
- if(threadpassfd >= 0){
- write(threadpassfd, "0", 1);
- close(threadpassfd);
- threadpassfd = -1;
- }
+ if(threadpassfd < 0)
+ sysfatal("threads in main proc exited w/o threadmaybackground");
+ write(threadpassfd, "0", 1);
+ close(threadpassfd);
+ threadpassfd = -1;
}