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