libthread: add threadmaybackground
Programs that want to background themselves now need to define threadmaybackground returning 1. This avoids a confusing (to people and debuggers) extra parent process for all the threaded programs that will never want to background themselves.
This commit is contained in:
parent
5b37d91264
commit
b3a20a96eb
19 changed files with 120 additions and 21 deletions
7
src/libthread/bg.c
Normal file
7
src/libthread/bg.c
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#include "threadimpl.h"
|
||||
|
||||
int
|
||||
threadmaybackground(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ SYSOFILES=`{sh ./sysofiles.sh}
|
|||
LIB=libthread.a
|
||||
OFILES=\
|
||||
$SYSOFILES\
|
||||
bg.$O\
|
||||
channel.$O\
|
||||
daemonize.$O\
|
||||
exec.$O\
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue