summaryrefslogtreecommitdiff
path: root/sys/src/cmd/srvfs.c
diff options
context:
space:
mode:
authorAlex Musolino <alex@musolino.id.au>2020-12-15 20:55:41 +1030
committerAlex Musolino <alex@musolino.id.au>2020-12-15 20:55:41 +1030
commit3749e92cdb88a157f99c0709a264bd508603be9b (patch)
tree49ce703965ba4114490729c5aeabd9ba120d9b78 /sys/src/cmd/srvfs.c
parent404c901f299c4d93cb159a3c44c2977a25408319 (diff)
parent32291b52bcbd6976051acff1692b571e321ac859 (diff)
merge
Diffstat (limited to 'sys/src/cmd/srvfs.c')
-rw-r--r--sys/src/cmd/srvfs.c45
1 files changed, 15 insertions, 30 deletions
diff --git a/sys/src/cmd/srvfs.c b/sys/src/cmd/srvfs.c
index d5c028150..a500c8ed2 100644
--- a/sys/src/cmd/srvfs.c
+++ b/sys/src/cmd/srvfs.c
@@ -12,7 +12,7 @@ void
main(int argc, char **argv)
{
char *ename, *arglist[16], **argp;
- int n, fd, pipefd[2];
+ int fd, pipefd[2];
char buf[64];
int perm = 0600;
@@ -39,14 +39,27 @@ main(int argc, char **argv)
*argp++ = "-R";
break;
}ARGEND
- *argp = 0;
if(argc != 2)
usage();
+ *argp++ = "-r";
+ *argp++ = argv[1];
+ *argp = 0;
if(pipe(pipefd) < 0){
fprint(2, "can't pipe: %r\n");
exits("pipe");
}
+ if(argv[0][0] == '/')
+ strecpy(buf, buf+sizeof buf, argv[0]);
+ else
+ snprint(buf, sizeof buf, "/srv/%s", argv[0]);
+ fd = create(buf, OWRITE|ORCLOSE, perm);
+ if(fd < 0){
+ fprint(2, "can't create %s: %r\n", buf);
+ exits("create");
+ }
+ fprint(fd, "%d", pipefd[1]);
+ close(pipefd[1]);
switch(rfork(RFPROC|RFNOWAIT|RFNOTEG|RFFDG)){
case -1:
@@ -56,39 +69,11 @@ main(int argc, char **argv)
dup(pipefd[0], 0);
dup(pipefd[0], 1);
close(pipefd[0]);
- close(pipefd[1]);
exec(ename, arglist);
fprint(2, "can't exec exportfs: %r\n");
exits("exec");
default:
break;
}
- close(pipefd[0]);
- if(fprint(pipefd[1], "%s", argv[1]) < 0){
- fprint(2, "can't write pipe: %r\n");
- exits("write");
- }
- n = read(pipefd[1], buf, sizeof buf-1);
- if(n < 0){
- fprint(2, "can't read pipe: %r\n");
- exits("read");
- }
- buf[n] = 0;
- if(n != 2 || strcmp(buf, "OK") != 0){
- fprint(2, "not OK (%d): %s\n", n, buf);
- exits("OK");
- }
- if(argv[0][0] == '/')
- strecpy(buf, buf+sizeof buf, argv[0]);
- else
- snprint(buf, sizeof buf, "/srv/%s", argv[0]);
- fd = create(buf, OWRITE, perm);
- if(fd < 0){
- fprint(2, "can't create %s: %r\n", buf);
- exits("create");
- }
- fprint(fd, "%d", pipefd[1]);
- close(fd);
- close(pipefd[1]);
exits(0);
}