4 Copyright (c) 2000 The Regents of the University of Michigan.
7 Copyright (c) 2000 Dug Song <dugsong@UMICH.EDU>.
8 Copyright (c) 2002 Andy Adamson <andros@UMICH.EDU>.
9 Copyright (c) 2002 Marius Aamodt Eriksen <marius@UMICH.EDU>.
10 Copyright (c) 2002 J. Bruce Fields <bfields@UMICH.EDU>.
11 All rights reserved, all wrongs reversed.
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions
17 1. Redistributions of source code must retain the above copyright
18 notice, this list of conditions and the following disclaimer.
19 2. Redistributions in binary form must reproduce the above copyright
20 notice, this list of conditions and the following disclaimer in the
21 documentation and/or other materials provided with the distribution.
22 3. Neither the name of the University nor the names of its
23 contributors may be used to endorse or promote products derived
24 from this software without specific prior written permission.
26 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
27 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
33 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 #endif /* HAVE_CONFIG_H */
44 #include <sys/param.h>
45 #include <sys/types.h>
47 #include <sys/socket.h>
66 * mydaemon creates a pipe between the partent and child
67 * process. The parent process will wait until the
68 * child dies or writes a '1' on the pipe signaling
69 * that it started successfully.
71 int pipefds[2] = { -1, -1};
74 mydaemon(int nochdir, int noclose)
76 int pid, status, tempfd;
78 if (pipe(pipefds) < 0) {
79 printerr(1, "mydaemon: pipe() failed: errno %d (%s)\n",
80 errno, strerror(errno));
83 if ((pid = fork ()) < 0) {
84 printerr(1, "mydaemon: fork() failed: errno %d (%s)\n",
85 errno, strerror(errno));
91 * Parent. Wait for status from child.
94 if (read(pipefds[0], &status, 1) != 1)
102 if (chdir ("/") == -1) {
103 printerr(1, "mydaemon: chdir() failed: errno %d (%s)\n",
104 errno, strerror(errno));
109 while (pipefds[1] <= 2) {
110 pipefds[1] = dup(pipefds[1]);
111 if (pipefds[1] < 0) {
112 printerr(1, "mydaemon: dup() failed: errno %d (%s)\n",
113 errno, strerror(errno));
119 tempfd = open("/dev/null", O_RDWR);
126 printerr(1, "mydaemon: can't open /dev/null: errno %d "
127 "(%s)\n", errno, strerror(errno));
140 if (pipefds[1] > 0) {
141 if (write(pipefds[1], &status, 1) != 1) {
143 "WARN: writing to parent pipe failed: errno %d (%s)\n",
144 errno, strerror(errno));
154 /* destroy krb5 machine creds */
155 printerr(1, "exiting on signal %d\n", signal);
162 /* don't exit on SIGHUP */
163 printerr(1, "Received SIGHUP... Ignoring.\n");
168 usage(char *progname)
170 fprintf(stderr, "usage: %s [-n] [-f] [-v] [-r] [-i]\n",
176 main(int argc, char *argv[])
181 int rpc_verbosity = 0;
182 int idmap_verbosity = 0;
187 while ((opt = getopt(argc, argv, "fivrnp:")) != -1) {
210 if ((progname = strrchr(argv[0], '/')))
215 initerr(progname, verbosity, fg);
216 #ifdef HAVE_AUTHGSS_SET_DEBUG_LEVEL
217 if (verbosity && rpc_verbosity == 0)
218 rpc_verbosity = verbosity;
219 authgss_set_debug_level(rpc_verbosity);
221 if (rpc_verbosity > 0)
222 printerr(0, "Warning: rpcsec_gss library does not "
223 "support setting debug level\n");
225 #ifdef HAVE_NFS4_SET_DEBUG
226 if (verbosity && idmap_verbosity == 0)
227 idmap_verbosity = verbosity;
228 nfs4_set_debug(idmap_verbosity, NULL);
230 if (idmap_verbosity > 0)
231 printerr(0, "Warning: your nfsidmap library does not "
232 "support setting debug level\n");
235 if (gssd_check_mechs() != 0) {
236 printerr(0, "ERROR: Problem with gssapi library\n");
243 signal(SIGINT, sig_die);
244 signal(SIGTERM, sig_die);
245 signal(SIGHUP, sig_hup);
247 if (get_creds && !gssd_acquire_cred(GSSD_SERVICE_NAME)) {
248 printerr(0, "unable to obtain root (machine) credentials\n");
249 printerr(0, "do you have a keytab entry for "
250 "nfs/<your.host>@<YOUR.REALM> in "
251 "/etc/krb5.keytab?\n");
259 printerr(0, "gssd_run returned!\n");