]> git.lizzy.rs Git - plan9front.git/commitdiff
dossrv, 9660srv, hjfs: stop *READING* standard *OUTPUT* with -s flag
authorcinap_lenrek <cinap_lenrek@felloff.net>
Sat, 7 Mar 2020 19:27:20 +0000 (20:27 +0100)
committercinap_lenrek <cinap_lenrek@felloff.net>
Sat, 7 Mar 2020 19:27:20 +0000 (20:27 +0100)
with the -s flag, we should read 9P messages from
standard *INPUT* (fd 0) and write responses to
standard *OUTPUT* (fd 1).

before these servers where reading from fd 1,
assuming they where both the same files.

sys/man/4/hjfs
sys/src/cmd/9660srv/main.c
sys/src/cmd/dossrv/fns.h
sys/src/cmd/dossrv/xfssrv.c
sys/src/cmd/hjfs/9p.c

index f3f132de112692be34b5f039ae6cf97d5a186af6..31a2ee2ea147c8357a30845d437aee69cdec3d79 100644 (file)
@@ -59,7 +59,7 @@ Ream the file system, erasing all of the old data.
 Ignore permissions.
 .TP
 .B -s
-Read and write protocol messages on file descriptor zero.
+Read and write protocol messages on standard file descriptors zero and one.
 .PD
 .SH SOURCE
 .B /sys/src/cmd/hjfs
index f3a9760f002073c46b09375941d65246f4198108..5daea3a8be64bb87c21f537491dda7e23e49f378 100644 (file)
@@ -11,7 +11,7 @@ enum
        Maxiosize       = IOHDRSZ+Maxfdata,
 };
 
-void io(int);
+void io(void);
 void rversion(void);
 void   rattach(void);
 void   rauth(void);
@@ -119,14 +119,7 @@ main(int argc, char **argv)
        for(xs=xsublist; *xs; xs++)
                (*(*xs)->reset)();
 
-       if(stdio) {
-               pipefd[0] = 0;
-               pipefd[1] = 1;
-       } else {
-               close(0);
-               close(1);
-               open("/dev/null", OREAD);
-               open("/dev/null", OWRITE);
+       if(!stdio){
                if(pipe(pipefd) < 0)
                        panic(1, "pipe");
                sprint(srvfile, "/srv/%s", srvname);
@@ -136,24 +129,25 @@ main(int argc, char **argv)
                fprint(srvfd, "%d", pipefd[0]);
                close(pipefd[0]);
                fprint(2, "%s %d: serving %s\n", argv0, getpid(), srvfile);
+               dup(pipefd[1], 0);
+               dup(pipefd[1], 1);
        }
-       srvfd = pipefd[1];
 
        switch(rfork(RFNOWAIT|RFNOTEG|RFFDG|RFPROC|RFNAMEG)){
        case -1:
                panic(1, "fork");
        default:
-               _exits(0);
+               _exits(nil);
        case 0:
                break;
        }
 
-       io(srvfd);
-       exits(0);
+       io();
+       exits(nil);
 }
 
 void
-io(int srvfd)
+io(void)
 {
        int n, pid;
        Fcall xreq, xrep;
@@ -163,7 +157,7 @@ io(int srvfd)
        pid = getpid();
        fmtinstall('F', fcallfmt);
 
-       while((n = read9pmsg(srvfd, mdata, sizeof mdata)) != 0){
+       while((n = read9pmsg(0, mdata, sizeof mdata)) != 0){
                if(n < 0)
                        panic(1, "mount read");
                if(convM2S(mdata, n, req) != n)
@@ -195,7 +189,7 @@ io(int srvfd)
                n = convS2M(rep, mdata, sizeof mdata);
                if(n == 0)
                        panic(1, "convS2M error on write");
-               if(write(srvfd, mdata, n) != n)
+               if(write(1, mdata, n) != n)
                        panic(1, "mount write");
                if(nerr_lab != 0)
                        panic(0, "err stack %d: %lux %lux %lux %lux %lux %lux", nerr_lab,
index 42a76f06f2f0833059006a0e2cb6590c3fc03952..092149e2e430510b6d2f02ef01fb0c6588572152 100644 (file)
@@ -26,7 +26,7 @@ char  *getnamesect(char*, char*, uchar*, int*, int*, int);
 long   getstart(Xfs *xf, Dosdir *d);
 Xfs    *getxfs(char*, char*);
 long   gtime(Dosdir *d);
-void   io(int srvfd);
+void   io(void);
 int    iscontig(Xfs *xf, Dosdir *d);
 int    isroot(vlong addr);
 int    makecontig(Xfile*, int);
index 7bceb74fc2d7efd03194530b667d2bb44aab039b..a173f80081f60ac2877477ad8e48c0203584a4a4 100644 (file)
@@ -18,7 +18,6 @@ char  repdata[Maxfdata];
 uchar  statbuf[STATMAX];
 int    errno;
 char   errbuf[ERRMAX];
-void   rmservice(void);
 char   srvfile[64];
 char   *deffile;
 int    doabort;
@@ -87,14 +86,9 @@ main(int argc, char **argv)
        else
                usage();
 
-       if(stdio){
-               pipefd[0] = 0;
-               pipefd[1] = 1;
-       }else{
-               close(0);
-               close(1);
-               open("/dev/null", OREAD);
-               open("/dev/null", OWRITE);
+       iotrack_init();
+
+       if(!stdio){
                if(pipe(pipefd) < 0)
                        panic("pipe");
                srvfd = create(srvfile, OWRITE|ORCLOSE, 0600);
@@ -102,40 +96,39 @@ main(int argc, char **argv)
                        panic(srvfile);
                fprint(srvfd, "%d", pipefd[0]);
                close(pipefd[0]);
-               atexit(rmservice);
                fprint(2, "%s: serving %s\n", argv0, srvfile);
+
+               dup(pipefd[1], 0);
+               dup(pipefd[1], 1);
        }
-       srvfd = pipefd[1];
 
        switch(rfork(RFNOWAIT|RFNOTEG|RFFDG|RFPROC|RFNAMEG)){
        case -1:
                panic("fork");
        default:
-               _exits(0);
+               _exits(nil);
        case 0:
                break;
        }
 
-       iotrack_init();
-
        if(!chatty){
                close(2);
                open("#c/cons", OWRITE);
        }
 
-       io(srvfd);
-       exits(0);
+       io();
+       exits(nil);
 }
 
 void
-io(int srvfd)
+io(void)
 {
        int n, pid;
 
        pid = getpid();
 
        fmtinstall('F', fcallfmt);
-       while((n = read9pmsg(srvfd, mdata, sizeof mdata)) != 0){
+       while((n = read9pmsg(0, mdata, sizeof mdata)) != 0){
                if(n < 0)
                        panic("mount read");
                if(convM2S(mdata, n, req) != n)
@@ -162,18 +155,12 @@ io(int srvfd)
                n = convS2M(rep, mdata, sizeof mdata);
                if(n == 0)
                        panic("convS2M error on write");
-               if(write(srvfd, mdata, n) != n)
+               if(write(1, mdata, n) != n)
                        panic("mount write");
        }
        chat("server shut down\n");
 }
 
-void
-rmservice(void)
-{
-       remove(srvfile);
-}
-
 char *
 xerrstr(int e)
 {
index ac3535740c626ef38a2b28d5885b2632732fd57d..ffa4ba3bd69b38ee06f5588dfcef55c8b00ec9ce 100644 (file)
@@ -142,7 +142,7 @@ start9p(char *service, char **nets, int stdio)
                threadlistensrv(&mysrv, *nets++);
        }
        if(stdio){
-               mysrv.infd = 1;
+               mysrv.infd = 0;
                mysrv.outfd = 1;
                srv(&mysrv);
        }else