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/games | |
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/games')
-rw-r--r-- | sys/src/games/music/jukefs/fs.c | 22 | ||||
-rw-r--r-- | sys/src/games/music/playlistfs/fs.c | 22 |
2 files changed, 12 insertions, 32 deletions
diff --git a/sys/src/games/music/jukefs/fs.c b/sys/src/games/music/jukefs/fs.c index bcfeb246b..744096520 100644 --- a/sys/src/games/music/jukefs/fs.c +++ b/sys/src/games/music/jukefs/fs.c @@ -684,35 +684,25 @@ newfid(int fid) void io(void *) { - char *err, e[32]; + char *err; int n; extern int p[]; Fid *f; threadsetname("file server"); close(p[1]); - 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(mfd[0], mdata, messagesize); - if(n == 0) - continue; + while((n = read9pmsg(mfd[0], mdata, messagesize)) != 0){ if(n < 0){ + char e[32]; rerrstr(e, sizeof e); if (strcmp(e, "interrupted") == 0){ if (debug & DbgFs) fprint(2, "read9pmsg interrupted\n"); continue; } - return; + sysfatal("mount read: %s", e); } - if(convM2S(mdata, n, &thdr) == 0) - continue; + if(convM2S(mdata, n, &thdr) != n) + sysfatal("convM2S format error: %r"); if(debug & DbgFs) fprint(2, "io:<-%F\n", &thdr); diff --git a/sys/src/games/music/playlistfs/fs.c b/sys/src/games/music/playlistfs/fs.c index 8a09074ba..47195e0df 100644 --- a/sys/src/games/music/playlistfs/fs.c +++ b/sys/src/games/music/playlistfs/fs.c @@ -725,7 +725,6 @@ allocwork(Req *r) void srvio(void *arg) { - char e[32]; int n; Req *r; Channel *dispatchc; @@ -734,34 +733,25 @@ srvio(void *arg) dispatchc = arg; r = reqalloc(); - 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(srvfd[0], r->indata, messagesize); - if(n == 0) - continue; + while((n = read9pmsg(srvfd[0], r->indata, messagesize)) != 0){ if(n < 0){ + char e[32]; rerrstr(e, sizeof e); if (strcmp(e, "interrupted") == 0){ if (debug & DbgFs) fprint(2, "read9pmsg interrupted\n"); continue; } - sysfatal("srvio: %s", e); + sysfatal("srvio: read: %s", e); } - if(convM2S(r->indata, n, &r->ifcall) == 0) - continue; + if(convM2S(r->indata, n, &r->ifcall) != n) + sysfatal("srvio: convM2S: %r"); if(debug & DbgFs) fprint(2, "io:<-%F\n", &r->ifcall); sendp(dispatchc, r); r = reqalloc(); } + threadexitsall(nil); } char * |