use threaddaemonize
This commit is contained in:
parent
96d6b19dcd
commit
7ffc5208a8
2 changed files with 9 additions and 26 deletions
|
|
@ -149,19 +149,8 @@ threadmain(int argc, char **argv)
|
||||||
if((afd = announce(addr, adir)) < 0)
|
if((afd = announce(addr, adir)) < 0)
|
||||||
sysfatal("announce %s: %r", addr);
|
sysfatal("announce %s: %r", addr);
|
||||||
|
|
||||||
if(verbose) fprint(2, "9pserve forking\n");
|
threaddaemonize();
|
||||||
switch(fork()){
|
mainproc(nil);
|
||||||
case -1:
|
|
||||||
sysfatal("fork: %r");
|
|
||||||
case 0:
|
|
||||||
if(verbose) fprint(2, "running mainproc\n");
|
|
||||||
mainproc(nil);
|
|
||||||
if(verbose) fprint(2, "mainproc finished\n");
|
|
||||||
_exits(0);
|
|
||||||
default:
|
|
||||||
if(verbose) fprint(2, "9pserve exiting\n");
|
|
||||||
_exits(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -220,6 +209,7 @@ listenthread(void *arg)
|
||||||
|
|
||||||
io = ioproc();
|
io = ioproc();
|
||||||
USED(arg);
|
USED(arg);
|
||||||
|
threadsetname("listen %s", adir);
|
||||||
for(;;){
|
for(;;){
|
||||||
c = emalloc(sizeof(Conn));
|
c = emalloc(sizeof(Conn));
|
||||||
c->fd = iolisten(io, adir, c->dir);
|
c->fd = iolisten(io, adir, c->dir);
|
||||||
|
|
@ -284,6 +274,7 @@ connthread(void *arg)
|
||||||
Ioproc *io;
|
Ioproc *io;
|
||||||
|
|
||||||
c = arg;
|
c = arg;
|
||||||
|
threadsetname("conn %s", c->dir);
|
||||||
io = ioproc();
|
io = ioproc();
|
||||||
fd = ioaccept(io, c->fd, c->dir);
|
fd = ioaccept(io, c->fd, c->dir);
|
||||||
if(fd < 0){
|
if(fd < 0){
|
||||||
|
|
@ -491,7 +482,7 @@ openfdthread(void *v)
|
||||||
c = v;
|
c = v;
|
||||||
fid = c->fdfid;
|
fid = c->fdfid;
|
||||||
io = ioproc();
|
io = ioproc();
|
||||||
|
threadsetname("openfd %s", c->fdfid);
|
||||||
tot = 0;
|
tot = 0;
|
||||||
m = nil;
|
m = nil;
|
||||||
if(c->fdmode == OREAD){
|
if(c->fdmode == OREAD){
|
||||||
|
|
@ -655,6 +646,7 @@ connoutthread(void *arg)
|
||||||
c = arg;
|
c = arg;
|
||||||
outq = c->outq;
|
outq = c->outq;
|
||||||
io = ioproc();
|
io = ioproc();
|
||||||
|
threadsetname("connout %s", c->dir);
|
||||||
while((m = recvq(outq)) != nil){
|
while((m = recvq(outq)) != nil){
|
||||||
err = m->tx.type+1 != m->rx.type;
|
err = m->tx.type+1 != m->rx.type;
|
||||||
if(!err && m->isopenfd)
|
if(!err && m->isopenfd)
|
||||||
|
|
@ -714,6 +706,7 @@ outputthread(void *arg)
|
||||||
|
|
||||||
USED(arg);
|
USED(arg);
|
||||||
io = ioproc();
|
io = ioproc();
|
||||||
|
threadsetname("output");
|
||||||
while((m = recvq(outq)) != nil){
|
while((m = recvq(outq)) != nil){
|
||||||
if(verbose > 1) fprint(2, "* <- %F\n", &m->tx);
|
if(verbose > 1) fprint(2, "* <- %F\n", &m->tx);
|
||||||
rewritehdr(&m->tx, m->tpkt);
|
rewritehdr(&m->tx, m->tpkt);
|
||||||
|
|
@ -734,6 +727,7 @@ inputthread(void *arg)
|
||||||
Msg *m;
|
Msg *m;
|
||||||
Ioproc *io;
|
Ioproc *io;
|
||||||
|
|
||||||
|
threadsetname("input");
|
||||||
if(verbose) fprint(2, "input thread\n");
|
if(verbose) fprint(2, "input thread\n");
|
||||||
io = ioproc();
|
io = ioproc();
|
||||||
USED(arg);
|
USED(arg);
|
||||||
|
|
|
||||||
|
|
@ -69,19 +69,8 @@ threadmain(int argc, char *argv[])
|
||||||
rules = readrules(plumbfile, fd);
|
rules = readrules(plumbfile, fd);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
/*
|
|
||||||
* Start all processes and threads from other proc
|
|
||||||
* so we (main pid) can return to user.
|
|
||||||
*/
|
|
||||||
if(dofork)
|
if(dofork)
|
||||||
switch(fork()){
|
threaddaemonize();
|
||||||
case -1:
|
|
||||||
sysfatal("fork: %r");
|
|
||||||
case 0:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
_exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
printerrors = 0;
|
printerrors = 0;
|
||||||
makeports(rules);
|
makeports(rules);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue