summaryrefslogtreecommitdiff
path: root/sys/src/cmd/aux
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2016-07-24 02:21:32 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2016-07-24 02:21:32 +0200
commita0d4c5e208405f84076891faaa43235bb2b87fc2 (patch)
tree9549cd4cd11c57e3c72d31f4a0424c75b1d5a063 /sys/src/cmd/aux
parenta840b597cad282e837560b65dad89aa0cfd4af77 (diff)
make error handling in 9p service loops consistent
when we get eof, stop the loop immidiately and do not rely on the read to eventually return an error. when convM2S() fails to decode the message, error out and stop the loop. there is no point in continuing.
Diffstat (limited to 'sys/src/cmd/aux')
-rw-r--r--sys/src/cmd/aux/9pcon.c2
-rw-r--r--sys/src/cmd/aux/consolefs.c17
-rw-r--r--sys/src/cmd/aux/depend.c19
-rw-r--r--sys/src/cmd/aux/searchfs.c22
4 files changed, 18 insertions, 42 deletions
diff --git a/sys/src/cmd/aux/9pcon.c b/sys/src/cmd/aux/9pcon.c
index f8bbf3c18..9edf26510 100644
--- a/sys/src/cmd/aux/9pcon.c
+++ b/sys/src/cmd/aux/9pcon.c
@@ -49,7 +49,7 @@ watch(int fd)
sysfatal("out of memory");
while((n = read9pmsg(fd, buf, messagesize)) > 0){
- if(convM2S(buf, n, &f) == 0){
+ if(convM2S(buf, n, &f) != n){
print("convM2S: %r\n");
continue;
}
diff --git a/sys/src/cmd/aux/consolefs.c b/sys/src/cmd/aux/consolefs.c
index ebc5e1230..feef1eef3 100644
--- a/sys/src/cmd/aux/consolefs.c
+++ b/sys/src/cmd/aux/consolefs.c
@@ -681,18 +681,13 @@ fsrun(void *v)
}
free(d);
r = allocreq(fs, messagesize);
- while((n = read9pmsg(fs->fd, r->buf, messagesize)) == 0)
- ;
+ n = read9pmsg(fs->fd, r->buf, messagesize);
+ if(n == 0)
+ threadexitsall("unmounted");
if(n < 0)
- fatal("unmounted");
-
- if(convM2S(r->buf, n, &r->f) == 0){
- fprint(2, "can't convert %ux %ux %ux\n", r->buf[0],
- r->buf[1], r->buf[2]);
- free(r);
- continue;
- }
-
+ fatal("mount read: %r");
+ if(convM2S(r->buf, n, &r->f) != n)
+ fatal("convM2S format error: %r");
f = fsgetfid(fs, r->f.fid);
r->fid = f;
diff --git a/sys/src/cmd/aux/depend.c b/sys/src/cmd/aux/depend.c
index 6132b2d22..0a06ed710 100644
--- a/sys/src/cmd/aux/depend.c
+++ b/sys/src/cmd/aux/depend.c
@@ -365,18 +365,14 @@ fsrun(void *a)
for(;;){
r = allocreq(messagesize);
qlock(&iolock);
- while((n = read9pmsg(fs->fd, r->buf, messagesize)) == 0)
- ;
- qunlock(&iolock);
+ n = read9pmsg(fs->fd, r->buf, messagesize);
+ if(n == 0)
+ threadexitsall("unmounted");
if(n < 0)
- fatal("read9pmsg error: %r");
-
- if(convM2S(r->buf, n, &r->f) == 0){
- fprint(2, "can't convert %ux %ux %ux\n", r->buf[0],
- r->buf[1], r->buf[2]);
- free(r);
- continue;
- }
+ fatal("mount read: %r");
+ if(convM2S(r->buf, n, &r->f) != n)
+ fatal("convM2S format error: %r");
+ qunlock(&iolock);
f = fsgetfid(fs, r->f.fid);
r->fid = f;
@@ -388,7 +384,6 @@ fsrun(void *a)
(*fcall[t])(fs, r, f);
fsputfid(fs, f);
}
-
}
/*
diff --git a/sys/src/cmd/aux/searchfs.c b/sys/src/cmd/aux/searchfs.c
index 7c1ad84f1..4a617f8e2 100644
--- a/sys/src/cmd/aux/searchfs.c
+++ b/sys/src/cmd/aux/searchfs.c
@@ -592,26 +592,12 @@ fsrun(Fs *fs, int fd)
int n;
buf = emalloc(messagesize);
- for(;;){
- /*
- * reading from a pipe or a network device
- * will give an error after a few eof reads
- * however, we cannot tell the difference
- * between a zero-length read and an interrupt
- * on the processes writing to us,
- * so we wait for the error
- */
- n = read9pmsg(fd, buf, messagesize);
- if(n == 0)
- continue;
+ while((n = read9pmsg(fd, buf, messagesize)) != 0){
if(n < 0)
- fatal("mount read");
-
+ fatal("mount read: %r");
rpc.data = (char*)buf + IOHDRSZ;
- if(convM2S(buf, n, &rpc) == 0)
- continue;
- // fprint(2, "recv: %F\n", &rpc);
-
+ if(convM2S(buf, n, &rpc) != n)
+ fatal("convM2S format error: %r");
/*
* flushes are way too hard.