summaryrefslogtreecommitdiff
path: root/sys/src/lib9p/post.c
diff options
context:
space:
mode:
authoraiju <aiju@phicode.de>2011-07-27 10:46:34 +0200
committeraiju <aiju@phicode.de>2011-07-27 10:46:34 +0200
commitabe6ead0ffc3167871d39d62502afe36e9a5d2c9 (patch)
treef6d5f26e5249b9629966f48280b95d106806ca84 /sys/src/lib9p/post.c
parentc08f86254ef0cce80eb9a532c25c50bf20bcc126 (diff)
lib9p: added functions for devshr
Diffstat (limited to 'sys/src/lib9p/post.c')
-rw-r--r--sys/src/lib9p/post.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/sys/src/lib9p/post.c b/sys/src/lib9p/post.c
index b42c7b32c..37dcfd5dc 100644
--- a/sys/src/lib9p/post.c
+++ b/sys/src/lib9p/post.c
@@ -56,6 +56,56 @@ _postmountsrv(Srv *s, char *name, char *mtpt, int flag)
close(s->srvfd);
}
+void
+_postsharesrv(Srv *s, char *name, char *mtpt, char *desc, char *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(sharefd(mtpt, desc, flag, s->srvfd) < 0)
+ sysfatal("sharefd %s: %r", mtpt);
+ }else
+ close(s->srvfd);
+}
+
+
static void
postproc(void *v)
{