shithub: riscv

ref: 28f3a3aad8d2d73010f1c81080e92f71903f4556
dir: /sys/src/lib9p/post.c/

View raw version
#include <u.h>
#include <libc.h>
#include <fcall.h>
#include <thread.h>
#include <9p.h>
#include <auth.h>

static void postproc(void*);

void
_postmountsrv(Srv *s, char *name, char *mtpt, int flag)
{
	int fd[2];

	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|RFNOTEG);

	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);
}

void
_postsharesrv(Srv *s, char *name, char *mtpt, char *desc)
{
	int fd[2];

	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|RFNOTEG);

	rfork(RFFDG);
	rendezvous(0, 0);

	close(s->infd);
	if(s->infd != s->outfd)
		close(s->outfd);

	if(mtpt){
		if(sharefd(mtpt, desc, s->srvfd) < 0)
			sysfatal("sharefd %s: %r", mtpt);
	}else
		close(s->srvfd);
}


static void
postproc(void *v)
{
	Srv *s;

	s = v;
	rendezvous(0, 0);
	close(s->srvfd);
	srv(s);
}