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>
23 #include <sys/socket.h>
24 #include <netinet/in.h>
25 #include <arpa/inet.h>
29 static void usage(const char *);
31 static struct option longopts[] =
33 { "host", 1, 0, 'H' },
34 { "help", 0, 0, 'h' },
35 { "no-nfs-version", 1, 0, 'N' },
36 { "no-tcp", 0, 0, 'T' },
37 { "no-udp", 0, 0, 'U' },
38 { "port", 1, 0, 'P' },
39 { "port", 1, 0, 'p' },
42 unsigned int protobits = NFSCTL_ALLBITS;
43 unsigned int versbits = NFSCTL_ALLBITS;
44 int minorvers4 = NFSD_MAXMINORVERS4; /* nfsv4 minor version */
48 main(int argc, char **argv)
50 int count = 1, c, error, port, fd, found_one;
55 ent = getservbyname ("nfs", "udp");
57 port = ntohs (ent->s_port);
61 while ((c = getopt_long(argc, argv, "H:hN:p:P:TU", longopts, NULL)) != EOF) {
64 if (inet_addr(optarg) != INADDR_NONE) {
65 haddr = strdup(optarg);
66 } else if ((hp = gethostbyname(optarg)) != NULL) {
67 haddr = inet_ntoa((*(struct in_addr*)(hp->h_addr_list[0])));
69 fprintf(stderr, "%s: Unknown hostname: %s\n",
74 case 'P': /* XXX for nfs-server compatibility */
77 if (port <= 0 || port > 65535) {
78 fprintf(stderr, "%s: bad port number: %s\n",
84 switch((c = strtol(optarg, &p, 0))) {
87 minorvers4 = -atoi(p + 1);
92 NFSCTL_VERUNSET(versbits, c);
95 fprintf(stderr, "%s: Unsupported version\n", optarg);
100 NFSCTL_TCPUNSET(protobits);
103 NFSCTL_UDPUNSET(protobits);
106 fprintf(stderr, "Invalid argument: '%c'\n", c);
112 * Do some sanity checking, if the ctlbits are set
114 if (!NFSCTL_UDPISSET(protobits) && !NFSCTL_TCPISSET(protobits)) {
115 fprintf(stderr, "invalid protocol specified\n");
119 for (c = NFSD_MINVERS; c <= NFSD_MAXVERS; c++) {
120 if (NFSCTL_VERISSET(versbits, c))
124 fprintf(stderr, "no version specified\n");
128 if (NFSCTL_VERISSET(versbits, 4) && !NFSCTL_TCPISSET(protobits)) {
129 fprintf(stderr, "version 4 requires the TCP protocol\n");
133 struct in_addr in = {INADDR_ANY};
134 haddr = strdup(inet_ntoa(in));
137 if (chdir(NFS_STATEDIR)) {
138 fprintf(stderr, "%s: chdir(%s) failed: %s\n",
139 argv [0], NFS_STATEDIR, strerror(errno));
144 if ((count = atoi(argv[optind])) < 0) {
145 /* insane # of servers */
147 "%s: invalid server count (%d), using 1\n",
153 Some kernels let nfsd kernel threads inherit open files
154 from the program that spawns them (i.e. us). So close
155 everything before spawning kernel threads. --Chip */
156 fd = open("/dev/null", O_RDWR);
166 openlog("nfsd", LOG_PID, LOG_DAEMON);
167 if ((error = nfssvc(port, count, versbits, minorvers4, protobits, haddr)) < 0) {
169 syslog(LOG_ERR, "nfssvc: %s", strerror(e));
177 usage(const char *prog)
179 fprintf(stderr, "Usage:\n"
180 "%s [-H hostname] [-p|-P|--port port] [-N|--no-nfs-version version ] [-T|--no-tcp] [-U|--no-udp] nrservs\n",