Fix the behavior of exportfs -r. Check the return of chdir(srv) to prevent exporting accidentally the current working directory when the directory specified with option -r doesn't exist. Also fix at the same time the missing trailing \n in error messages printed just before exits(). Reference: /n/sources/patch/applied/exportfs-chdir Date: Sat Feb 9 14:22:03 CET 2013 Signed-off-by: djc@9grid.fr --- /sys/src/cmd/exportfs/exportfs.c Sat Feb 9 14:21:51 2013 +++ /sys/src/cmd/exportfs/exportfs.c Sat Feb 9 14:21:46 2013 @@ -254,7 +254,12 @@ /* do nothing */ } else if(srv) { - chdir(srv); + if(chdir(srv) < 0) { + errstr(ebuf, sizeof ebuf); + fprint(0, "chdir(\"%s\"): %s\n", srv, ebuf); + DEBUG(DFD, "chdir(\"%s\"): %s\n", srv, ebuf); + exits(ebuf); + } DEBUG(DFD, "invoked as server for %s", srv); strncpy(buf, srv, sizeof buf); } @@ -264,15 +269,15 @@ n = read(0, buf, sizeof(buf)-1); if(n < 0) { errstr(buf, sizeof buf); - fprint(0, "read(0): %s", buf); - DEBUG(DFD, "read(0): %s", buf); + fprint(0, "read(0): %s\n", buf); + DEBUG(DFD, "read(0): %s\n", buf); exits(buf); } buf[n] = 0; if(chdir(buf) < 0) { errstr(ebuf, sizeof ebuf); - fprint(0, "chdir(%d:\"%s\"): %s", n, buf, ebuf); - DEBUG(DFD, "chdir(%d:\"%s\"): %s", n, buf, ebuf); + fprint(0, "chdir(%d:\"%s\"): %s\n", n, buf, ebuf); + DEBUG(DFD, "chdir(%d:\"%s\"): %s\n", n, buf, ebuf); exits(ebuf); } }