4 * This is the user level part of nfsd. This is very primitive, because
5 * all the work is now done in the kernel module.
7 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
22 #include <sys/socket.h>
23 #include <netinet/in.h>
24 #include <arpa/inet.h>
30 static void usage(const char *);
32 static struct option longopts[] =
34 { "host", 1, 0, 'H' },
35 { "help", 0, 0, 'h' },
36 { "no-nfs-version", 1, 0, 'N' },
37 { "no-tcp", 0, 0, 'T' },
38 { "no-udp", 0, 0, 'U' },
39 { "port", 1, 0, 'P' },
40 { "port", 1, 0, 'p' },
41 { "debug", 0, 0, 'd' },
42 { "syslog", 0, 0, 's' },
45 unsigned int protobits = NFSCTL_ALLBITS;
46 unsigned int versbits = NFSCTL_ALLBITS;
47 int minorvers4 = NFSD_MAXMINORVERS4; /* nfsv4 minor version */
51 main(int argc, char **argv)
53 int count = 1, c, error, port, fd, found_one;
58 ent = getservbyname ("nfs", "udp");
60 port = ntohs (ent->s_port);
64 progname = strdup(basename(argv[0]));
66 fprintf(stderr, "%s: unable to allocate memory.\n", argv[0]);
73 while ((c = getopt_long(argc, argv, "dH:hN:p:P:sTU", longopts, NULL)) != EOF) {
76 xlog_config(D_ALL, 1);
79 if (inet_addr(optarg) != INADDR_NONE) {
80 haddr = strdup(optarg);
81 } else if ((hp = gethostbyname(optarg)) != NULL) {
82 haddr = inet_ntoa((*(struct in_addr*)(hp->h_addr_list[0])));
84 fprintf(stderr, "%s: Unknown hostname: %s\n",
89 case 'P': /* XXX for nfs-server compatibility */
92 if (port <= 0 || port > 65535) {
93 fprintf(stderr, "%s: bad port number: %s\n",
99 switch((c = strtol(optarg, &p, 0))) {
102 minorvers4 = -atoi(p + 1);
107 NFSCTL_VERUNSET(versbits, c);
110 fprintf(stderr, "%s: Unsupported version\n", optarg);
119 NFSCTL_TCPUNSET(protobits);
122 NFSCTL_UDPUNSET(protobits);
125 fprintf(stderr, "Invalid argument: '%c'\n", c);
134 * Do some sanity checking, if the ctlbits are set
136 if (!NFSCTL_UDPISSET(protobits) && !NFSCTL_TCPISSET(protobits)) {
137 xlog(L_ERROR, "invalid protocol specified");
141 for (c = NFSD_MINVERS; c <= NFSD_MAXVERS; c++) {
142 if (NFSCTL_VERISSET(versbits, c))
146 xlog(L_ERROR, "no version specified");
150 if (NFSCTL_VERISSET(versbits, 4) && !NFSCTL_TCPISSET(protobits)) {
151 xlog(L_ERROR, "version 4 requires the TCP protocol");
155 struct in_addr in = {INADDR_ANY};
156 haddr = strdup(inet_ntoa(in));
159 if (chdir(NFS_STATEDIR)) {
160 xlog(L_ERROR, "chdir(%s) failed: %m", NFS_STATEDIR);
165 if ((count = atoi(argv[optind])) < 0) {
166 /* insane # of servers */
167 xlog(L_ERROR, "invalid server count (%d), using 1",
173 Some kernels let nfsd kernel threads inherit open files
174 from the program that spawns them (i.e. us). So close
175 everything before spawning kernel threads. --Chip */
176 fd = open("/dev/null", O_RDWR);
178 xlog(L_ERROR, "Unable to open /dev/null: %m");
180 /* switch xlog output to syslog since stderr is being closed */
189 if ((error = nfssvc(port, count, versbits, minorvers4, protobits, haddr)) < 0)
190 xlog(L_ERROR, "nfssvc: errno %d (%m)", errno);
197 usage(const char *prog)
199 fprintf(stderr, "Usage:\n"
200 "%s [-d|--debug] [-H hostname] [-p|-P|--port port] [-N|--no-nfs-version version ] [-s|--syslog] [-T|--no-tcp] [-U|--no-udp] nrservs\n",