diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cmd/9pfuse/main.c | 6 | ||||
-rw-r--r-- | src/cmd/9pserve.c | 6 | ||||
-rw-r--r-- | src/cmd/auth/factotum/main.c | 6 | ||||
-rw-r--r-- | src/cmd/auth/ssh-agent.c | 6 | ||||
-rw-r--r-- | src/cmd/fossil/fossil.c | 6 | ||||
-rw-r--r-- | src/cmd/import.c | 6 | ||||
-rw-r--r-- | src/cmd/ndb/dns.c | 6 | ||||
-rw-r--r-- | src/cmd/plumb/plumber.c | 6 | ||||
-rw-r--r-- | src/cmd/smugfs/main.c | 6 | ||||
-rw-r--r-- | src/cmd/upas/fs/fs.c | 6 | ||||
-rw-r--r-- | src/cmd/upas/nfs/main.c | 6 | ||||
-rw-r--r-- | src/cmd/venti/srv/venti.c | 6 | ||||
-rw-r--r-- | src/lib9p/ramfs.c | 6 | ||||
-rw-r--r-- | src/libthread/bg.c | 7 | ||||
-rw-r--r-- | src/libthread/daemonize.c | 12 | ||||
-rw-r--r-- | src/libthread/mkfile | 1 | ||||
-rw-r--r-- | src/libthread/thread.c | 2 |
17 files changed, 93 insertions, 7 deletions
diff --git a/src/cmd/9pfuse/main.c b/src/cmd/9pfuse/main.c index 69d1ad75..4fa330a0 100644 --- a/src/cmd/9pfuse/main.c +++ b/src/cmd/9pfuse/main.c @@ -98,6 +98,12 @@ usage(void) void fusereader(void*); void watchfd(void*); +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char **argv) { diff --git a/src/cmd/9pserve.c b/src/cmd/9pserve.c index 255bcbb2..e26eef14 100644 --- a/src/cmd/9pserve.c +++ b/src/cmd/9pserve.c @@ -137,6 +137,12 @@ usage(void) threadexitsall("usage"); } +int +threadmaybackground(void) +{ + return 1; +} + uchar vbuf[128]; extern int _threaddebuglevel; void diff --git a/src/cmd/auth/factotum/main.c b/src/cmd/auth/factotum/main.c index b3ace12c..6dfc2a40 100644 --- a/src/cmd/auth/factotum/main.c +++ b/src/cmd/auth/factotum/main.c @@ -20,6 +20,12 @@ usage(void) threadexitsall("usage"); } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char *argv[]) { diff --git a/src/cmd/auth/ssh-agent.c b/src/cmd/auth/ssh-agent.c index c3b0c7ef..e944e390 100644 --- a/src/cmd/auth/ssh-agent.c +++ b/src/cmd/auth/ssh-agent.c @@ -90,6 +90,12 @@ usage(void) threadexitsall("usage"); } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char **argv) { diff --git a/src/cmd/fossil/fossil.c b/src/cmd/fossil/fossil.c index 002e8510..c5672c86 100644 --- a/src/cmd/fossil/fossil.c +++ b/src/cmd/fossil/fossil.c @@ -59,6 +59,12 @@ readCmdPart(char *file, char ***pcmd, int *pncmd) *pncmd = ncmd; } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char* argv[]) { diff --git a/src/cmd/import.c b/src/cmd/import.c index 0be2f5b6..7da70966 100644 --- a/src/cmd/import.c +++ b/src/cmd/import.c @@ -51,6 +51,12 @@ fatal(char *fmt, ...) threadexitsall("fatal"); } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char *argv[]) { diff --git a/src/cmd/ndb/dns.c b/src/cmd/ndb/dns.c index cb317052..723989b9 100644 --- a/src/cmd/ndb/dns.c +++ b/src/cmd/ndb/dns.c @@ -121,6 +121,12 @@ checkaddress(void) fprint(2, "warning: announce mismatch %s %s\n", udpaddr, tcpaddr); } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char *argv[]) { diff --git a/src/cmd/plumb/plumber.c b/src/cmd/plumb/plumber.c index c99282f0..5ead2e93 100644 --- a/src/cmd/plumb/plumber.c +++ b/src/cmd/plumb/plumber.c @@ -26,6 +26,12 @@ makeports(Ruleset *rules[]) addport(rules[i]->port); } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char *argv[]) { diff --git a/src/cmd/smugfs/main.c b/src/cmd/smugfs/main.c index e1c2745f..31c9a752 100644 --- a/src/cmd/smugfs/main.c +++ b/src/cmd/smugfs/main.c @@ -51,6 +51,12 @@ smuglogin(void) printerrors = 0; } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char **argv) { diff --git a/src/cmd/upas/fs/fs.c b/src/cmd/upas/fs/fs.c index dc6ff3ba..32968e67 100644 --- a/src/cmd/upas/fs/fs.c +++ b/src/cmd/upas/fs/fs.c @@ -155,6 +155,12 @@ notifyf(void *a, char *s) noted(NDFLT); } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char *argv[]) { diff --git a/src/cmd/upas/nfs/main.c b/src/cmd/upas/nfs/main.c index c72a4849..68ae141b 100644 --- a/src/cmd/upas/nfs/main.c +++ b/src/cmd/upas/nfs/main.c @@ -26,6 +26,12 @@ usage(void) threadexitsall("usage"); } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char **argv) { diff --git a/src/cmd/venti/srv/venti.c b/src/cmd/venti/srv/venti.c index 1725537a..67fda91e 100644 --- a/src/cmd/venti/srv/venti.c +++ b/src/cmd/venti/srv/venti.c @@ -23,6 +23,12 @@ usage(void) threadexitsall("usage"); } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char *argv[]) { diff --git a/src/lib9p/ramfs.c b/src/lib9p/ramfs.c index b7a07c7d..7cf6489d 100644 --- a/src/lib9p/ramfs.c +++ b/src/lib9p/ramfs.c @@ -125,6 +125,12 @@ usage(void) threadexitsall("usage"); } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char **argv) { diff --git a/src/libthread/bg.c b/src/libthread/bg.c new file mode 100644 index 00000000..2edbc0e4 --- /dev/null +++ b/src/libthread/bg.c @@ -0,0 +1,7 @@ +#include "threadimpl.h" + +int +threadmaybackground(void) +{ + return 0; +} diff --git a/src/libthread/daemonize.c b/src/libthread/daemonize.c index 387d1527..f994ffe1 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 @@ -163,9 +163,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; } diff --git a/src/libthread/mkfile b/src/libthread/mkfile index 8a77a316..eca4f4df 100644 --- a/src/libthread/mkfile +++ b/src/libthread/mkfile @@ -4,6 +4,7 @@ SYSOFILES=`{sh ./sysofiles.sh} LIB=libthread.a OFILES=\ $SYSOFILES\ + bg.$O\ channel.$O\ daemonize.$O\ exec.$O\ diff --git a/src/libthread/thread.c b/src/libthread/thread.c index 65e65194..7151e875 100644 --- a/src/libthread/thread.c +++ b/src/libthread/thread.c @@ -844,7 +844,7 @@ main(int argc, char **argv) // Easier to just run in pthread-per-thread mode. pthreadperthread = 1; #endif - if(strstr(opts, "nodaemon") == nil && getenv("NOLIBTHREADDAEMONIZE") == nil) + if(threadmaybackground() && strstr(opts, "nodaemon") == nil && getenv("NOLIBTHREADDAEMONIZE") == nil) _threadsetupdaemonize(); threadargc = argc; |