rpc.nfsd to write to /proc/fs/nfs/threads if available
[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/nfs/threads", O_WRONLY);
23         if (fd >= 0) {
24                 /* 2.5+ kernel with nfsd filesystem mounted.
25                  * Just write the number in.
26                  * Cannot handle port number yet, but does anyone care?
27                  */
28                 char buf[20];
29                 int n;
30                 snprintf(buf, 20,"%d\n", nrservs);
31                 n = write(fd, buf, strlen(buf));
32                 close(fd);
33                 if (n != strlen(buf))
34                         return -1;
35                 else
36                         return 0;
37         }
38
39         arg.ca_version = NFSCTL_VERSION;
40         arg.ca_svc.svc_nthreads = nrservs;
41         arg.ca_svc.svc_port = port;
42         return nfsctl(NFSCTL_SVC, &arg, NULL);
43 }