mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-15 11:20:03 +00:00
a995e477ff
The main change is the use of pthread to implement ffork.
45 lines
706 B
C
45 lines
706 B
C
#include <sched.h>
|
|
#include <signal.h>
|
|
#include <lib9.h>
|
|
|
|
int fforkstacksize = 16384;
|
|
|
|
int
|
|
ffork(int flags, void (*fn)(void*), void *arg)
|
|
{
|
|
char *p;
|
|
int cloneflag, pid;
|
|
|
|
p = malloc(fforkstacksize);
|
|
if(p == nil)
|
|
return -1;
|
|
cloneflag = 0;
|
|
flags &= ~RFPROC;
|
|
if(flags&RFMEM){
|
|
cloneflag |= CLONE_VM;
|
|
flags &= ~RFMEM;
|
|
}
|
|
if(!(flags&RFFDG))
|
|
cloneflag |= CLONE_FILES;
|
|
else
|
|
flags &= ~RFFDG;
|
|
if(!(flags&RFNOWAIT))
|
|
cloneflag |= SIGCHLD;
|
|
else
|
|
flags &= ~RFNOWAIT;
|
|
if(flags){
|
|
fprint(2, "unknown rfork flags %x\n", flags);
|
|
return -1;
|
|
}
|
|
pid = clone((int(*)(void*))fn, p+fforkstacksize-16, cloneflag, arg);
|
|
if(pid < 0)
|
|
free(p);
|
|
return pid;
|
|
}
|
|
|
|
int
|
|
getfforkid(void)
|
|
{
|
|
return getpid();
|
|
}
|
|
|