different fix for main proc bug
This commit is contained in:
parent
8da6bca807
commit
8ee6ad4d96
3 changed files with 22 additions and 12 deletions
|
|
@ -121,7 +121,6 @@ _threadsetupdaemonize(void)
|
||||||
close(p[1]);
|
close(p[1]);
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
for(i=0; i<100; i++) sched_yield();
|
|
||||||
notedisable("sys: child");
|
notedisable("sys: child");
|
||||||
signal(SIGCHLD, SIG_DFL);
|
signal(SIGCHLD, SIG_DFL);
|
||||||
/* rfork(RFNOTEG); */
|
/* rfork(RFNOTEG); */
|
||||||
|
|
|
||||||
|
|
@ -281,6 +281,24 @@ procscheduler(Proc *p)
|
||||||
|
|
||||||
Out:
|
Out:
|
||||||
_threaddebug("scheduler exit");
|
_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);
|
delproc(p);
|
||||||
lock(&threadnproclock);
|
lock(&threadnproclock);
|
||||||
if(p->sysproc)
|
if(p->sysproc)
|
||||||
|
|
@ -298,7 +316,7 @@ _threadsetsysproc(void)
|
||||||
{
|
{
|
||||||
lock(&threadnproclock);
|
lock(&threadnproclock);
|
||||||
if(++threadnsysproc == threadnproc)
|
if(++threadnsysproc == threadnproc)
|
||||||
exit(0);
|
threadexitsall(nil);
|
||||||
unlock(&threadnproclock);
|
unlock(&threadnproclock);
|
||||||
proc()->sysproc = 1;
|
proc()->sysproc = 1;
|
||||||
}
|
}
|
||||||
|
|
@ -576,21 +594,13 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
_pthreadinit();
|
_pthreadinit();
|
||||||
p = procalloc();
|
p = procalloc();
|
||||||
|
p->mainproc = 1;
|
||||||
_threadsetproc(p);
|
_threadsetproc(p);
|
||||||
if(mainstacksize == 0)
|
if(mainstacksize == 0)
|
||||||
mainstacksize = 256*1024;
|
mainstacksize = 256*1024;
|
||||||
_threadcreate(p, threadmainstart, nil, mainstacksize);
|
_threadcreate(p, threadmainstart, nil, mainstacksize);
|
||||||
procscheduler(p);
|
procscheduler(p);
|
||||||
_threaddaemonize();
|
/* does not return */
|
||||||
/*
|
|
||||||
* 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();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,7 @@ struct Proc
|
||||||
Context schedcontext;
|
Context schedcontext;
|
||||||
void *udata;
|
void *udata;
|
||||||
Jmp sigjmp;
|
Jmp sigjmp;
|
||||||
|
int mainproc;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define proc() _threadproc()
|
#define proc() _threadproc()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue