aboutsummaryrefslogtreecommitdiff
path: root/src/libthread/thread.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2005-02-14 18:58:56 +0000
committerrsc <devnull@localhost>2005-02-14 18:58:56 +0000
commit8ee6ad4d96bdb1f56cece8c11e75e5491ccc4020 (patch)
tree45c988326892ac25c58aeabef8128cc9828a5957 /src/libthread/thread.c
parent8da6bca8074977c0fd1105ca4da2d5fb225b3ec4 (diff)
downloadplan9port-8ee6ad4d96bdb1f56cece8c11e75e5491ccc4020.tar.gz
plan9port-8ee6ad4d96bdb1f56cece8c11e75e5491ccc4020.tar.bz2
plan9port-8ee6ad4d96bdb1f56cece8c11e75e5491ccc4020.zip
different fix for main proc bug
Diffstat (limited to 'src/libthread/thread.c')
-rw-r--r--src/libthread/thread.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/libthread/thread.c b/src/libthread/thread.c
index c07a84f3..57ffa1cb 100644
--- a/src/libthread/thread.c
+++ b/src/libthread/thread.c
@@ -281,6 +281,24 @@ procscheduler(Proc *p)
Out:
_threaddebug("scheduler exit");
+ if(p->mainproc){
+ /*
+ * Stupid bug - on Linux 2.6 and maybe elsewhere,
+ * if the main thread exits then the others keep running
+ * but the process shows up as a zombie in ps and is not
+ * attachable with ptrace. We'll just sit around pretending
+ * to be a system proc instead of exiting.
+ */
+ _threaddaemonize();
+ lock(&threadnproclock);
+ if(++threadnsysproc == threadnproc)
+ threadexitsall(p->msg);
+ p->sysproc = 1;
+ unlock(&threadnproclock);
+ for(;;)
+ sleep(1000);
+ }
+
delproc(p);
lock(&threadnproclock);
if(p->sysproc)
@@ -298,7 +316,7 @@ _threadsetsysproc(void)
{
lock(&threadnproclock);
if(++threadnsysproc == threadnproc)
- exit(0);
+ threadexitsall(nil);
unlock(&threadnproclock);
proc()->sysproc = 1;
}
@@ -576,21 +594,13 @@ main(int argc, char **argv)
_pthreadinit();
p = procalloc();
+ p->mainproc = 1;
_threadsetproc(p);
if(mainstacksize == 0)
mainstacksize = 256*1024;
_threadcreate(p, threadmainstart, nil, mainstacksize);
procscheduler(p);
- _threaddaemonize();
- /*
- * On Linux 2.6, if the main thread exits then the others
- * keep running but the process shows up as a zombie in ps
- * and is not attachable with ptrace. We'll just sit around
- * instead of exiting.
- */
- for(;;)
- sleep(1000);
- _threadpexit();
+ /* does not return */
return 0;
}