Blame


1 2277c5d7 2004-03-21 devnull #include <u.h>
2 2277c5d7 2004-03-21 devnull #include <libc.h>
3 2277c5d7 2004-03-21 devnull #include <fcall.h>
4 2277c5d7 2004-03-21 devnull #include <thread.h>
5 2277c5d7 2004-03-21 devnull #include <9p.h>
6 2277c5d7 2004-03-21 devnull #include "post.h"
7 2277c5d7 2004-03-21 devnull
8 2277c5d7 2004-03-21 devnull Postcrud*
9 2277c5d7 2004-03-21 devnull _post1(Srv *s, char *name, char *mtpt, int flag)
10 2277c5d7 2004-03-21 devnull {
11 2277c5d7 2004-03-21 devnull Postcrud *p;
12 2277c5d7 2004-03-21 devnull
13 2277c5d7 2004-03-21 devnull p = emalloc9p(sizeof *p);
14 2277c5d7 2004-03-21 devnull if(!s->nopipe){
15 2277c5d7 2004-03-21 devnull if(pipe(p->fd) < 0)
16 2277c5d7 2004-03-21 devnull sysfatal("pipe: %r");
17 2277c5d7 2004-03-21 devnull s->infd = s->outfd = p->fd[1];
18 2277c5d7 2004-03-21 devnull s->srvfd = p->fd[0];
19 2277c5d7 2004-03-21 devnull }
20 2277c5d7 2004-03-21 devnull if(name)
21 2277c5d7 2004-03-21 devnull if(postfd(name, s->srvfd) < 0)
22 2277c5d7 2004-03-21 devnull sysfatal("postfd %s: %r", name);
23 2277c5d7 2004-03-21 devnull p->s = s;
24 2277c5d7 2004-03-21 devnull p->mtpt = mtpt;
25 2277c5d7 2004-03-21 devnull p->flag = flag;
26 2277c5d7 2004-03-21 devnull return p;
27 2277c5d7 2004-03-21 devnull }
28 2277c5d7 2004-03-21 devnull
29 2277c5d7 2004-03-21 devnull void
30 2277c5d7 2004-03-21 devnull _post2(void *v)
31 2277c5d7 2004-03-21 devnull {
32 2277c5d7 2004-03-21 devnull Srv *s;
33 2277c5d7 2004-03-21 devnull
34 2277c5d7 2004-03-21 devnull s = v;
35 2277c5d7 2004-03-21 devnull if(!s->leavefdsopen){
36 5c8a0421 2004-12-26 devnull rfork(RFNOTEG);
37 2277c5d7 2004-03-21 devnull rendezvous((ulong)s, 0);
38 2277c5d7 2004-03-21 devnull close(s->srvfd);
39 2277c5d7 2004-03-21 devnull }
40 2277c5d7 2004-03-21 devnull srv(s);
41 2277c5d7 2004-03-21 devnull }
42 2277c5d7 2004-03-21 devnull
43 2277c5d7 2004-03-21 devnull void
44 2277c5d7 2004-03-21 devnull _post3(Postcrud *p)
45 2277c5d7 2004-03-21 devnull {
46 2277c5d7 2004-03-21 devnull /*
47 2277c5d7 2004-03-21 devnull * Normally the server is posting as the last thing it does
48 2277c5d7 2004-03-21 devnull * before exiting, so the correct thing to do is drop into
49 2277c5d7 2004-03-21 devnull * a different fd space and close the 9P server half of the
50 2277c5d7 2004-03-21 devnull * pipe before trying to mount the kernel half. This way,
51 2277c5d7 2004-03-21 devnull * if the file server dies, we don't have a ref to the 9P server
52 2277c5d7 2004-03-21 devnull * half of the pipe. Then killing the other procs will drop
53 2277c5d7 2004-03-21 devnull * all the refs on the 9P server half, and the mount will fail.
54 2277c5d7 2004-03-21 devnull * Otherwise the mount hangs forever.
55 2277c5d7 2004-03-21 devnull *
56 2277c5d7 2004-03-21 devnull * Libthread in general and acme win in particular make
57 2277c5d7 2004-03-21 devnull * it hard to make this fd bookkeeping work out properly,
58 2277c5d7 2004-03-21 devnull * so leaveinfdopen is a flag that win sets to opt out of this
59 2277c5d7 2004-03-21 devnull * safety net.
60 2277c5d7 2004-03-21 devnull */
61 2277c5d7 2004-03-21 devnull if(!p->s->leavefdsopen){
62 2277c5d7 2004-03-21 devnull rfork(RFFDG);
63 2277c5d7 2004-03-21 devnull rendezvous((ulong)p->s, 0);
64 2277c5d7 2004-03-21 devnull close(p->s->infd);
65 2277c5d7 2004-03-21 devnull if(p->s->infd != p->s->outfd)
66 2277c5d7 2004-03-21 devnull close(p->s->outfd);
67 2277c5d7 2004-03-21 devnull }
68 2277c5d7 2004-03-21 devnull
69 9bddce0e 2006-06-26 devnull #if 0
70 2277c5d7 2004-03-21 devnull if(p->mtpt){
71 2277c5d7 2004-03-21 devnull if(amount(p->s->srvfd, p->mtpt, p->flag, "") == -1)
72 2277c5d7 2004-03-21 devnull sysfatal("mount %s: %r", p->mtpt);
73 2277c5d7 2004-03-21 devnull }else
74 9bddce0e 2006-06-26 devnull #endif
75 2277c5d7 2004-03-21 devnull close(p->s->srvfd);
76 2277c5d7 2004-03-21 devnull free(p);
77 2277c5d7 2004-03-21 devnull }