]> git.decadent.org.uk Git - nfs-utils.git/blob - utils/nfsd/nfsd.c
2001-05-28 H.J. Lu <hjl@lucon.org>
[nfs-utils.git] / utils / nfsd / nfsd.c
1 /*
2  * nfsd
3  *
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.
6  *
7  * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
8  */
9
10 #include "config.h"
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <unistd.h>
15 #include <string.h>
16 #include <errno.h>
17 #include <getopt.h>
18 #include "nfslib.h"
19
20 static void     usage(const char *);
21
22 int
23 main(int argc, char **argv)
24 {
25         int     count = 1, c, error, port;
26
27         port = 2049;
28
29         /* FIXME: Check for nfs in /etc/services */
30
31         while ((c = getopt(argc, argv, "hp:P:")) != EOF) {
32                 switch(c) {
33                 case 'P':       /* XXX for nfs-server compatibility */
34                 case 'p':
35                         port = atoi(optarg);
36                         if (port <= 0 || port > 65535) {
37                                 fprintf(stderr, "%s: bad port number: %s\n",
38                                         argv[0], optarg);
39                                 usage(argv [0]);
40                         }
41                         break;
42                         break;
43                 case 'h':
44                 default:
45                         usage(argv[0]);
46                 }
47         }
48
49         if (chdir(NFS_STATEDIR)) {
50                 fprintf(stderr, "%s: chdir(%s) failed: %s\n",
51                         argv [0], NFS_STATEDIR, strerror(errno));
52                 exit(1);
53         }
54
55         if (optind < argc) {
56                 if ((count = atoi(argv[optind])) < 0) {
57                         /* insane # of servers */
58                         fprintf(stderr,
59                                 "%s: invalid server count (%d), using 1\n",
60                                 argv[0], count);
61                         count = 1;
62                 }
63         }
64
65         if ((error = nfssvc(port, count)) < 0)
66                 perror("nfssvc");
67
68         return (error != 0);
69 }
70
71 static void
72 usage(const char *prog)
73 {
74         fprintf(stderr, "usage:\n"
75                         "%s nrservs\n", prog);
76         exit(2);
77 }