Blob


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