]> git.lizzy.rs Git - plan9front.git/blob - sys/src/lib9p/post.c
libaml: fix gc bug, need to amltake()/amldrop() temporary buffer
[plan9front.git] / sys / src / lib9p / post.c
1 #include <u.h>
2 #include <libc.h>
3 #include <fcall.h>
4 #include <thread.h>
5 #include <9p.h>
6
7 static void
8 postproc(void *v)
9 {
10         Srv *s = v;
11         close((int)(uintptr)rendezvous(s, 0));
12         srv(s);
13 }
14
15 int
16 postsrv(Srv *s, char *name)
17 {
18         int fd[2], cfd;
19
20         if(pipe(fd) < 0)
21                 return -1;
22         if(name != nil){
23                 char buf[80];
24
25                 snprint(buf, sizeof buf, "/srv/%s", name);
26                 if((cfd = create(buf, OWRITE|ORCLOSE|OCEXEC, 0600)) < 0
27                 || fprint(cfd, "%d", fd[0]) < 0){
28                         close(fd[0]);
29                         fd[0] = -1;
30                         goto Out;
31                 }
32         } else
33                 cfd = -1;
34
35         /* now we are commited */
36         s->infd = s->outfd = fd[1];
37         if(s->forker == nil)
38                 s->forker = srvforker;
39         (*s->forker)(postproc, s, RFNAMEG|RFNOTEG);
40
41         rfork(RFFDG);
42         rendezvous(s, (void*)(uintptr)fd[0]);
43 Out:
44         if(cfd >= 0)
45                 close(cfd);
46         close(fd[1]);
47         return fd[0];
48 }