diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2016-07-24 02:21:32 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2016-07-24 02:21:32 +0200 |
commit | a0d4c5e208405f84076891faaa43235bb2b87fc2 (patch) | |
tree | 9549cd4cd11c57e3c72d31f4a0424c75b1d5a063 /sys/src/cmd/ratfs/proto.c | |
parent | a840b597cad282e837560b65dad89aa0cfd4af77 (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/ratfs/proto.c')
-rw-r--r-- | sys/src/cmd/ratfs/proto.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/sys/src/cmd/ratfs/proto.c b/sys/src/cmd/ratfs/proto.c index 7ed046fdd..21abbc282 100644 --- a/sys/src/cmd/ratfs/proto.c +++ b/sys/src/cmd/ratfs/proto.c @@ -56,16 +56,14 @@ io(void) Fcall rhdr; int n; - for(;;){ - n = read9pmsg(srvfd, rbuf, sizeof rbuf-1); - if(n <= 0) - fatal("mount read"); - if(convM2S(rbuf, n, &rhdr) == 0){ + while((n = read9pmsg(srvfd, rbuf, sizeof rbuf-1)) != 0){ + if(n < 0) + fatal("mount read: %r"); + if(convM2S(rbuf, n, &rhdr) != n){ if(debugfd >= 0) fprint(2, "%s: malformed message\n", argv0); - continue; + fatal("convM2S format error: %r"); } - if(debugfd >= 0) fprint(debugfd, "<-%F\n", &rhdr);/**/ @@ -94,9 +92,9 @@ reply(Fcall *r, char *error) fprint(debugfd, "->%F\n", r);/**/ n = convS2M(r, rbuf, sizeof rbuf); if(n == 0) - sysfatal("convS2M: %r"); + fatal("convS2M: %r"); if(write(srvfd, rbuf, n) < 0) - sysfatal("reply: %r"); + fatal("reply: %r"); } |