/proc/fs/nfsd as an alternate to /proc/fs/nfsd
[nfs-utils.git] / support / nfs / nfssvc.c
1 /*
2  * support/nfs/nfssvc.c
3  *
4  * Run an NFS daemon.
5  *
6  * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
7  */
8
9 #include "config.h"
10
11 #include <unistd.h>
12 #include <fcntl.h>
13
14 #include "nfslib.h"
15
16 int
17 nfssvc(int port, int nrservs)
18 {
19         struct nfsctl_arg       arg;
20         int fd;
21
22         fd = open("/proc/fs/nfsd/threads", O_WRONLY);
23         if (fd < 0)
24                 fd = open("/proc/fs/nfs/threads", O_WRONLY);
25         if (fd >= 0) {
26                 /* 2.5+ kernel with nfsd filesystem mounted.
27                  * Just write the number in.
28                  * Cannot handle port number yet, but does anyone care?
29                  */
30                 char buf[20];
31                 int n;
32                 snprintf(buf, 20,"%d\n", nrservs);
33                 n = write(fd, buf, strlen(buf));
34                 close(fd);
35                 if (n != strlen(buf))
36                         return -1;
37                 else
38                         return 0;
39         }
40
41         arg.ca_version = NFSCTL_VERSION;
42         arg.ca_svc.svc_nthreads = nrservs;
43         arg.ca_svc.svc_port = port;
44         return nfsctl(NFSCTL_SVC, &arg, NULL);
45 }