summaryrefslogtreecommitdiff
path: root/sys/src/lib9p/post.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2021-05-01 19:58:58 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2021-05-01 19:58:58 +0200
commitee289c241577a3553bfd73211cd81e137ab4fe40 (patch)
tree8f40ebfb2769de543c133120c5dbc468beddc9eb /sys/src/lib9p/post.c
parent57c21ae441d1b6af38ce310ffec87340488ed84b (diff)
lib9p: remove Srv.srvfd, make postsrv() and threadpostsrv() return the mountable file descriptor, update documentation
Now that we have these new functions, we can also make them return an error instead of calling sysfatal() like postmountsrv(). Remove the confusing Srv.srvfd, as it is only temporarily used and return it from postsrv() instead.
Diffstat (limited to 'sys/src/lib9p/post.c')
-rw-r--r--sys/src/lib9p/post.c38
1 files changed, 18 insertions, 20 deletions
diff --git a/sys/src/lib9p/post.c b/sys/src/lib9p/post.c
index 18ded63ba..b2134968c 100644
--- a/sys/src/lib9p/post.c
+++ b/sys/src/lib9p/post.c
@@ -8,43 +8,41 @@ static void
postproc(void *v)
{
Srv *s = v;
- rendezvous(0, 0);
- close(s->srvfd);
+ close((int)(uintptr)rendezvous(s, 0));
srv(s);
}
-void
+int
postsrv(Srv *s, char *name)
{
- char buf[80];
- int fd[2];
- int cfd;
+ int fd[2], cfd;
if(pipe(fd) < 0)
- sysfatal("pipe: %r");
- s->infd = s->outfd = fd[1];
- s->srvfd = fd[0];
-
+ return -1;
if(name != nil){
+ char buf[80];
+
snprint(buf, sizeof buf, "/srv/%s", name);
- if((cfd = create(buf, OWRITE|ORCLOSE|OCEXEC, 0600)) < 0)
- sysfatal("create %s: %r", buf);
- if(fprint(cfd, "%d", s->srvfd) < 0)
- sysfatal("write %s: %r", buf);
+ if((cfd = create(buf, OWRITE|ORCLOSE|OCEXEC, 0600)) < 0
+ || fprint(cfd, "%d", fd[0]) < 0){
+ close(fd[0]);
+ fd[0] = -1;
+ goto Out;
+ }
} else
cfd = -1;
+ /* now we are commited */
+ s->infd = s->outfd = fd[1];
if(s->forker == nil)
s->forker = srvforker;
(*s->forker)(postproc, s, RFNAMEG|RFNOTEG);
rfork(RFFDG);
- rendezvous(0, 0);
-
- close(s->infd);
- if(s->infd != s->outfd)
- close(s->outfd);
-
+ rendezvous(s, (void*)(uintptr)fd[0]);
+Out:
if(cfd >= 0)
close(cfd);
+ close(fd[1]);
+ return fd[0];
}