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