2004-04-21 04:48:25 +00:00
|
|
|
#include <u.h>
|
|
|
|
#include <libc.h>
|
|
|
|
#include "9proc.h"
|
|
|
|
#undef rfork
|
2003-11-23 18:12:54 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
p9rfork(int flags)
|
|
|
|
{
|
2003-12-04 00:17:10 +00:00
|
|
|
int pid;
|
|
|
|
|
|
|
|
if((flags&(RFPROC|RFFDG|RFMEM)) == (RFPROC|RFFDG)){
|
|
|
|
/* check other flags before we commit */
|
|
|
|
flags &= ~(RFPROC|RFFDG);
|
2003-12-11 17:48:38 +00:00
|
|
|
if(flags & ~(RFNOTEG|RFNAMEG)){
|
2003-12-04 00:17:10 +00:00
|
|
|
werrstr("unknown flags %08ux in rfork", flags);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
pid = fork();
|
2004-04-21 04:48:25 +00:00
|
|
|
_p9uproc(0);
|
2003-12-04 00:17:10 +00:00
|
|
|
if(pid != 0)
|
|
|
|
return pid;
|
|
|
|
}
|
2003-11-23 18:12:54 +00:00
|
|
|
if(flags&RFPROC){
|
2003-12-11 17:48:38 +00:00
|
|
|
werrstr("cannot use rfork for shared memory -- use ffork");
|
2003-11-23 18:12:54 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2003-12-11 17:48:38 +00:00
|
|
|
if(flags&RFNAMEG){
|
|
|
|
/* XXX set $NAMESPACE to a new directory */
|
|
|
|
flags &= ~RFNAMEG;
|
|
|
|
}
|
2003-11-23 18:12:54 +00:00
|
|
|
if(flags&RFNOTEG){
|
2003-11-23 19:49:17 +00:00
|
|
|
setpgid(0, getpid());
|
2003-11-23 18:12:54 +00:00
|
|
|
flags &= ~RFNOTEG;
|
|
|
|
}
|
|
|
|
if(flags){
|
|
|
|
werrstr("unknown flags %08ux in rfork", flags);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|