restore old plan 9 property that when the
last thread exits the main proc, the remaining program ends up in the background and the program appears to have exited.
This commit is contained in:
parent
07bda1263e
commit
1d2533d010
6 changed files with 36 additions and 8 deletions
|
|
@ -346,6 +346,13 @@ _pthreadinit(void)
|
||||||
signal(SIGUSR2, sigusr2handler);
|
signal(SIGUSR2, sigusr2handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_threadpexit(void)
|
||||||
|
{
|
||||||
|
_exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* FreeBSD 4 and earlier needs the context functions.
|
* FreeBSD 4 and earlier needs the context functions.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -348,3 +348,8 @@ _pthreadinit(void)
|
||||||
signal(SIGUSR2, sigusr2handler);
|
signal(SIGUSR2, sigusr2handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_threadpexit(void)
|
||||||
|
{
|
||||||
|
_exit(0);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,13 @@ static int threadpassfd;
|
||||||
static void
|
static void
|
||||||
child(void)
|
child(void)
|
||||||
{
|
{
|
||||||
int status;
|
int status, pid;
|
||||||
if(wait(&status) == sigpid)
|
pid = wait(&status);
|
||||||
if(WIFEXITED(status))
|
if(pid < 0)
|
||||||
|
fprint(2, "wait: %r\n");
|
||||||
|
else if(WIFEXITED(status))
|
||||||
_exit(WEXITSTATUS(status));
|
_exit(WEXITSTATUS(status));
|
||||||
|
print("pid %d if %d %d\n", pid, WIFEXITED(status), WEXITSTATUS(status));
|
||||||
_exit(97);
|
_exit(97);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -51,6 +54,7 @@ _threadsetupdaemonize(void)
|
||||||
if(fcntl(p[0], F_SETFD, 1) < 0 || fcntl(p[1], F_SETFD, 1) < 0)
|
if(fcntl(p[0], F_SETFD, 1) < 0 || fcntl(p[1], F_SETFD, 1) < 0)
|
||||||
sysfatal("passer pipe pipe fcntl: %r");
|
sysfatal("passer pipe pipe fcntl: %r");
|
||||||
|
|
||||||
|
signal(SIGCHLD, sigpass);
|
||||||
switch(pid = fork()){
|
switch(pid = fork()){
|
||||||
case -1:
|
case -1:
|
||||||
sysfatal("passer fork: %r");
|
sysfatal("passer fork: %r");
|
||||||
|
|
@ -58,6 +62,7 @@ _threadsetupdaemonize(void)
|
||||||
close(p[1]);
|
close(p[1]);
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
|
signal(SIGCHLD, SIG_DFL);
|
||||||
rfork(RFNOTEG);
|
rfork(RFNOTEG);
|
||||||
close(p[0]);
|
close(p[0]);
|
||||||
threadpassfd = p[1];
|
threadpassfd = p[1];
|
||||||
|
|
@ -89,7 +94,9 @@ _threadsetupdaemonize(void)
|
||||||
void
|
void
|
||||||
threaddaemonize(void)
|
threaddaemonize(void)
|
||||||
{
|
{
|
||||||
|
if(threadpassfd >= 0){
|
||||||
write(threadpassfd, "0", 1);
|
write(threadpassfd, "0", 1);
|
||||||
close(threadpassfd);
|
close(threadpassfd);
|
||||||
threadpassfd = -1;
|
threadpassfd = -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -132,3 +132,8 @@ threadexitsall(char *msg)
|
||||||
exits(msg);
|
exits(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_threadpexit(void)
|
||||||
|
{
|
||||||
|
pthread_exit(0);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -476,6 +476,8 @@ main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
Proc *p;
|
Proc *p;
|
||||||
|
|
||||||
|
argv0 = argv[0];
|
||||||
|
|
||||||
_threadsetupdaemonize();
|
_threadsetupdaemonize();
|
||||||
|
|
||||||
threadargc = argc;
|
threadargc = argc;
|
||||||
|
|
@ -503,7 +505,8 @@ main(int argc, char **argv)
|
||||||
mainstacksize = 65536;
|
mainstacksize = 65536;
|
||||||
_threadcreate(p, threadmainstart, nil, mainstacksize);
|
_threadcreate(p, threadmainstart, nil, mainstacksize);
|
||||||
scheduler(p);
|
scheduler(p);
|
||||||
return 0; /* not reached */
|
threaddaemonize();
|
||||||
|
_threadpexit();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -122,3 +122,4 @@ extern int _threadspawn(int*, char*, char**);
|
||||||
extern int _runthreadspawn(int*, char*, char**);
|
extern int _runthreadspawn(int*, char*, char**);
|
||||||
extern void _threadsetupdaemonize(void);
|
extern void _threadsetupdaemonize(void);
|
||||||
extern void _threaddodaemonize(char*);
|
extern void _threaddodaemonize(char*);
|
||||||
|
extern void _threadpexit(void);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue