]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/exportfs/exportfs.c
exportfs, oexportfs, iostats: make -d log to stderr
[plan9front.git] / sys / src / cmd / exportfs / exportfs.c
1 #include <u.h>
2 #include <libc.h>
3 #include <fcall.h>
4 #define Extern
5 #include "exportfs.h"
6
7 int     srvfd = -1;
8 int     readonly;
9
10 void
11 usage(void)
12 {
13         fprint(2, "usage: %s [-dsR] [-m msize] [-r root] "
14                 "[-P patternfile] [-S srvfile]\n", argv0);
15         fatal("usage");
16 }
17
18 void
19 main(int argc, char **argv)
20 {
21         char *srv, *srvfdfile;
22
23         srv = nil;
24         srvfd = -1;
25         srvfdfile = nil;
26
27         ARGBEGIN{
28         case 'd':
29                 dbg++;
30                 break;
31
32         case 'm':
33                 messagesize = strtoul(EARGF(usage()), nil, 0);
34                 break;
35
36         case 'r':
37                 srv = EARGF(usage());
38                 break;
39
40         case 's':
41                 srv = "/";
42                 break;
43
44         case 'F':
45                 /* accepted but ignored, for backwards compatibility */
46                 break;
47
48         case 'P':
49                 patternfile = EARGF(usage());
50                 break;
51
52         case 'R':
53                 readonly = 1;
54                 break;
55
56         case 'S':
57                 if(srvfdfile != nil)
58                         usage();
59                 srvfdfile = EARGF(usage());
60                 break;
61
62         default:
63                 usage();
64         }ARGEND
65         USED(argc, argv);
66
67         if(srvfdfile != nil){
68                 if(srv != nil){
69                         fprint(2, "exportfs: -S cannot be used with -r or -s\n");
70                         usage();
71                 }
72                 if((srvfd = open(srvfdfile, ORDWR)) < 0)
73                         fatal("open %s: %r", srvfdfile);
74         } else if(srv == nil)
75                 usage();
76
77         exclusions();
78
79         DEBUG(2, "exportfs: started\n");
80
81         rfork(RFNOTEG|RFREND);
82
83         if(messagesize == 0){
84                 messagesize = iounit(0);
85                 if(messagesize == 0)
86                         messagesize = 8192+IOHDRSZ;
87         }
88         fhash = emallocz(sizeof(Fid*)*FHASHSIZE);
89
90         fmtinstall('F', fcallfmt);
91
92         if(srvfd == -1) {
93                 if(chdir(srv) < 0) {
94                         char ebuf[ERRMAX];
95                         ebuf[0] = '\0';
96                         errstr(ebuf, sizeof ebuf);
97                         DEBUG(2, "chdir(\"%s\"): %s\n", srv, ebuf);
98                         mounterror(ebuf);
99                 }
100                 DEBUG(2, "invoked as server for %s", srv);
101         }
102
103         DEBUG(2, "\niniting root\n");
104         initroot();
105         io();
106 }