ARGBEGIN {
case 'c':
conffile = ARGF();
break;
case 'd':
debugfd = 2; /* stderr*/
break;
case 'f':
ctlfile = ARGF();
break;
case 'm':
mountpoint = ARGF();
break;
} ARGEND
if(argc != 0)
usage();
fmtinstall('I', eipfmt);
fmtinstall('M', eipfmt);
setroot();
getconf();
reload();
/* get a pipe and mount it in /srv */
if(pipe(p) < 0)
fatal("pipe failed: %r");
srvfd = p[0];
post(p[1], mountpoint);
/* start the 9fs protocol */
switch(rfork(RFPROC|RFNAMEG|RFENVG|RFFDG|RFNOTEG|RFREND)){
case -1:
fatal("fork: %r");
case 0:
/* seal off standard input/output */
close(0);
open("/dev/null", OREAD);
close(1);
open("/dev/null", OWRITE);
static void
setroot(void)
{
Filetree *fp;
Node *np;
int qid;
root = 0;
qid = Qaddr;
for(fp = filetree; fp->name; fp++) {
switch(fp->level) {
case 0: /* root */
case 1: /* second level directory */
newnode(root, fp->name, fp->type, fp->mode, fp->qid);
break;
case 2: /* lay down the Ipaddr and Acctaddr subdirectories */
for (np = root->children; np; np = np->sibs){
if(np->d.type == Addrdir)
newnode(np, fp->name, fp->type, fp->mode, qid++);
}
break;
default:
fatal("bad filetree");
}
}
dummy.d.type = Dummynode;
dummy.d.mode = 0444;
dummy.d.uid = "upas";
dummy.d.gid = "upas";
dummy.d.atime = dummy.d.mtime = time(0);
dummy.d.qid.path = Qdummy; /* for now */
}
static void
post(int fd, char *mountpoint)
{
int f;
char buf[128];
if(access(SRVFILE,0) >= 0){
/*
* If we can open and mount the /srv node,
* another server is already running, so just exit.
*/
f = open(SRVFILE, ORDWR);
if(f >= 0 && mount(f, -1, mountpoint, MREPL|MCREATE, "") != -1){
unmount(0, mountpoint);
exits(0);
}
remove(SRVFILE);
}
/*
* create the server node and post our pipe to it
*/
f = create(SRVFILE, OWRITE, 0666);
if(f < 0)
fatal("can't create %s", SRVFILE);