plan9fox/sys/src/cmd/exportfs/exportfs.c
amavect 0f58e47551 exportfs, oexportfs, iostats: make -d log to stderr
exportfs -d logs 9p traffic to /tmp/exportdb.
-f allows writing to a different file.
exportfs silently continues if it doesn't have
permissions to create or write to /tmp/exportdb.
These are poor behaviors.

A better default is to write to stderr, since it
is 9P debug info that is better immediately printed,
and not user info that is better handled by syslog().
As a result, -f is obsolete and thus removed.
Redirect responsibility is now on rc.
As a side effect, rc will fail if it doesn't
have permissions to write.

exportfs(4) is updated to reflect all changes
and with a better Synopsis.

oexportfs is changed to match exportfs.
oexportfs(4) is updated to reflect all changes.
The Synopsis is not changed due to the number of flags.

Removed -f from iostats.
iostats(4) is updated to reflect all changes.
---
2021-08-18 17:51:40 +00:00

107 lines
1.6 KiB
C

#include <u.h>
#include <libc.h>
#include <fcall.h>
#define Extern
#include "exportfs.h"
int srvfd = -1;
int readonly;
void
usage(void)
{
fprint(2, "usage: %s [-dsR] [-m msize] [-r root] "
"[-P patternfile] [-S srvfile]\n", argv0);
fatal("usage");
}
void
main(int argc, char **argv)
{
char *srv, *srvfdfile;
srv = nil;
srvfd = -1;
srvfdfile = nil;
ARGBEGIN{
case 'd':
dbg++;
break;
case 'm':
messagesize = strtoul(EARGF(usage()), nil, 0);
break;
case 'r':
srv = EARGF(usage());
break;
case 's':
srv = "/";
break;
case 'F':
/* accepted but ignored, for backwards compatibility */
break;
case 'P':
patternfile = EARGF(usage());
break;
case 'R':
readonly = 1;
break;
case 'S':
if(srvfdfile != nil)
usage();
srvfdfile = EARGF(usage());
break;
default:
usage();
}ARGEND
USED(argc, argv);
if(srvfdfile != nil){
if(srv != nil){
fprint(2, "exportfs: -S cannot be used with -r or -s\n");
usage();
}
if((srvfd = open(srvfdfile, ORDWR)) < 0)
fatal("open %s: %r", srvfdfile);
} else if(srv == nil)
usage();
exclusions();
DEBUG(2, "exportfs: started\n");
rfork(RFNOTEG|RFREND);
if(messagesize == 0){
messagesize = iounit(0);
if(messagesize == 0)
messagesize = 8192+IOHDRSZ;
}
fhash = emallocz(sizeof(Fid*)*FHASHSIZE);
fmtinstall('F', fcallfmt);
if(srvfd == -1) {
if(chdir(srv) < 0) {
char ebuf[ERRMAX];
ebuf[0] = '\0';
errstr(ebuf, sizeof ebuf);
DEBUG(2, "chdir(\"%s\"): %s\n", srv, ebuf);
mounterror(ebuf);
}
DEBUG(2, "invoked as server for %s", srv);
}
DEBUG(2, "\niniting root\n");
initroot();
io();
}