]> git.decadent.org.uk Git - nfs-utils.git/blob - support/nfs/nfssvc.c
Further coverity related cleanups.
[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 #ifdef HAVE_CONFIG_H
10 #include <config.h>
11 #endif
12
13 #include <unistd.h>
14 #include <fcntl.h>
15
16 #include "nfslib.h"
17
18 int
19 nfssvc(int port, int nrservs)
20 {
21         struct nfsctl_arg       arg;
22         int fd;
23
24         fd = open("/proc/fs/nfsd/threads", O_WRONLY);
25         if (fd < 0)
26                 fd = open("/proc/fs/nfs/threads", O_WRONLY);
27         if (fd >= 0) {
28                 /* 2.5+ kernel with nfsd filesystem mounted.
29                  * Just write the number in.
30                  * Cannot handle port number yet, but does anyone care?
31                  */
32                 char buf[20];
33                 int n;
34                 snprintf(buf, 20,"%d\n", nrservs);
35                 n = write(fd, buf, strlen(buf));
36                 close(fd);
37                 if (n != strlen(buf))
38                         return -1;
39                 else
40                         return 0;
41         }
42
43         arg.ca_version = NFSCTL_VERSION;
44         arg.ca_svc.svc_nthreads = nrservs;
45         arg.ca_svc.svc_port = port;
46         return nfsctl(NFSCTL_SVC, &arg, NULL);
47 }