aboutsummaryrefslogtreecommitdiff
path: root/src/lib9p/_post.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2004-03-21 04:33:13 +0000
committerrsc <devnull@localhost>2004-03-21 04:33:13 +0000
commit2277c5d7bbe1f9595fad512d8f790708473a9bf1 (patch)
tree4d653e13906f1971d3170dba6dbe0fbf92eb48d6 /src/lib9p/_post.c
parenta770daa795754cb600ad3fab2fdd2961147006c4 (diff)
downloadplan9port-2277c5d7bbe1f9595fad512d8f790708473a9bf1.tar.gz
plan9port-2277c5d7bbe1f9595fad512d8f790708473a9bf1.tar.bz2
plan9port-2277c5d7bbe1f9595fad512d8f790708473a9bf1.zip
Small tweaks
Lots of new code imported.
Diffstat (limited to 'src/lib9p/_post.c')
-rw-r--r--src/lib9p/_post.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/lib9p/_post.c b/src/lib9p/_post.c
new file mode 100644
index 00000000..e8313be1
--- /dev/null
+++ b/src/lib9p/_post.c
@@ -0,0 +1,77 @@
+#include <u.h>
+#include <libc.h>
+#include <fcall.h>
+#include <thread.h>
+#include <9p.h>
+#include <auth.h>
+#include "post.h"
+
+Postcrud*
+_post1(Srv *s, char *name, char *mtpt, int flag)
+{
+ Postcrud *p;
+
+ p = emalloc9p(sizeof *p);
+ if(!s->nopipe){
+ if(pipe(p->fd) < 0)
+ sysfatal("pipe: %r");
+ s->infd = s->outfd = p->fd[1];
+ s->srvfd = p->fd[0];
+ }
+ if(name)
+ if(postfd(name, s->srvfd) < 0)
+ sysfatal("postfd %s: %r", name);
+ p->s = s;
+ p->mtpt = mtpt;
+ p->flag = flag;
+ return p;
+}
+
+void
+_post2(void *v)
+{
+ Srv *s;
+
+ s = v;
+ rfork(RFNOTEG);
+ if(!s->leavefdsopen){
+ rendezvous((ulong)s, 0);
+ close(s->srvfd);
+ }
+ srv(s);
+}
+
+void
+_post3(Postcrud *p)
+{
+ /*
+ * 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(!p->s->leavefdsopen){
+ rfork(RFFDG);
+ rendezvous((ulong)p->s, 0);
+ close(p->s->infd);
+ if(p->s->infd != p->s->outfd)
+ close(p->s->outfd);
+ }
+
+ if(p->mtpt){
+ if(amount(p->s->srvfd, p->mtpt, p->flag, "") == -1)
+ sysfatal("mount %s: %r", p->mtpt);
+ }else
+ close(p->s->srvfd);
+ free(p);
+}
+