ref: d67b1c7ecb14d025f262edbcbab4b92d54f8b397
dir: /ns.c/
#include <u.h> #include <libc.h> #include <auth.h> #include "pro.h" static void usage(char *argv0) { fprint(2, "usage: %s\n", argv0); exits("usage"); } void main(int argc, char **argv) { Proconf *conf; int i, fd, pipefd[2]; if(argc != 1) usage(argv[0]); conf = pconf(); if(conf == nil){ fprint(2, "can't parse: %r\n"); exits("config"); } for(i = 0; i < conf->nstub; i++){ print(conf->stubs[i]); if(rfork(RFPROC|RFNOWAIT|RFNOTEG|RFNAMEG) == 0){ execl("/bin/aux/stub", "aux/stub", "-d", conf->stubs[i]); fprint(2, "can't exec aux/stub: %r\n"); } } if(addns(getuser(), ".pro/ns") < 0){ fprint(2, "can't addns: %r\n"); exits("addns"); } if(pipe(pipefd) < 0){ fprint(2, "can't pipe: %r\n"); exits("pipe"); } if(access(conf->sfile, 0) == 0) remove(conf->sfile); fd = create(conf->sfile, OWRITE|ORCLOSE, 0600); if(fd < 0){ fprint(2, "can't create %s: %r\n", conf->sfile); exits("create"); } fprint(fd, "%d", pipefd[1]); close(pipefd[1]); freeconf(conf); switch(rfork(RFPROC|RFNOWAIT|RFNOTEG|RFREND)){ case -1: fprint(2, "can't rfork: %r\n"); exits("rfork"); case 0: dup(pipefd[0], 0); dup(pipefd[0], 1); close(pipefd[0]); execl("/bin/exportfs", "exportfs", "-r", "."); fprint(2, "can't exec exportfs: %r\n"); exits("exec"); default: break; } exits(0); }