コード例 #1
0
ファイル: trfs.c プロジェクト: CoryXie/nix-os
void
main(int argc, char* argv[])
{
	char*	srv = nil;
	char*	sname = nil;
	char*	addr = nil;
	int	fd;
	int	p[2];

	ARGBEGIN{
	case 'D':
		debug = 1;
		break;
	case 'n':
		addr = EARGF(usage());
		break;
	case 'v':
		verbose = 1;
		break;
	case 's':
		sname = EARGF(usage());
		break;
	default:
		altspc = ARGC();
	}ARGEND;
	if (addr == nil){
		if (argc < 1)
			usage();
		srv = *argv;
		argc--;
	}
	if (argc > 0)
		usage();
	if (sname == nil)
		sname = (addr != nil) ? addr : "trfs";
	fmtinstall('D', dirfmt);
	fmtinstall('M', dirmodefmt);
	fmtinstall('F', fcallfmt);

	if (addr == nil)
		fd = open(srv, ORDWR);
	else
		fd = dial(netmkaddr(addr, "net", "9fs"), 0, 0, 0);
	if (fd < 0 || pipe(p) < 0)
		sysfatal("can't connect to  server %s: %r\n", (addr?addr:srv));
	if (postfd(sname, p[0]) < 0)
		sysfatal("can't post srv: %r\n");
	rfork(RFNOTEG);
	switch(rfork(RFPROC|RFNOTEG)){
	case 0:
		service(p[1], fd, 2);
		break;
	case -1:
		sysfatal("can't fork server: %r\n");
		break;
	}
	exits(nil);	
}
コード例 #2
0
ファイル: post.c プロジェクト: aahud/harvey
void
_postmountsrv(Srv *s, char *name, char *mtpt, int flag)
{
	int fd[2];

	if(!s->nopipe){
		if(pipe(fd) < 0)
			sysfatal("pipe: %r");
		s->infd = s->outfd = fd[1];
		s->srvfd = fd[0];
	}
	if(name)
		if(postfd(name, s->srvfd) < 0)
			sysfatal("postfd %s: %r", name);

	if(_forker == nil)
		sysfatal("no forker");
	_forker(postproc, s, RFNAMEG);

	/*
	 * Normally the server is posting as the last thing it does
	 * before exiting, so the correct thing to do is drop into
	 * a different fd space and close the 9P server half of the
	 * pipe before trying to mount the kernel half.  This way,
	 * if the file server dies, we don't have a ref to the 9P server
	 * half of the pipe.  Then killing the other procs will drop
	 * all the refs on the 9P server half, and the mount will fail.
	 * Otherwise the mount hangs forever.
	 *
	 * Libthread in general and acme win in particular make
	 * it hard to make this fd bookkeeping work out properly,
	 * so leaveinfdopen is a flag that win sets to opt out of this
	 * safety net.
	 */
	if(!s->leavefdsopen){
		rfork(RFFDG);
		rendezvous(0, 0);
		close(s->infd);
		if(s->infd != s->outfd)
			close(s->outfd);
	}

	if(mtpt){
		if(amount(s->srvfd, mtpt, flag, "") == -1)
			sysfatal("mount %s: %r", mtpt);
	}else
		close(s->srvfd);
}