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 #include <sys/param.h>
43 #include <sys/types.h>
45 #include <sys/socket.h>
65 DIR *dir = opendir("/proc/self/fd");
70 while ((d = readdir(dir)) != NULL) {
72 long n = strtol(d->d_name, &endp, 10);
73 if (*endp != '\0' && n >= min && n != dfd)
78 int fd = sysconf(_SC_OPEN_MAX);
85 * mydaemon creates a pipe between the partent and child
86 * process. The parent process will wait until the
87 * child dies or writes a '1' on the pipe signaling
88 * that it started successfully.
90 int pipefds[2] = { -1, -1};
93 mydaemon(int nochdir, int noclose)
95 int pid, status, tempfd;
97 if (pipe(pipefds) < 0) {
98 printerr(1, "mydaemon: pipe() failed: errno %d (%s)\n",
99 errno, strerror(errno));
102 if ((pid = fork ()) < 0) {
103 printerr(1, "mydaemon: fork() failed: errno %d (%s)\n",
104 errno, strerror(errno));
110 * Parent. Wait for status from child.
113 if (read(pipefds[0], &status, 1) != 1)
121 if (chdir ("/") == -1) {
122 printerr(1, "mydaemon: chdir() failed: errno %d (%s)\n",
123 errno, strerror(errno));
128 while (pipefds[1] <= 2) {
129 pipefds[1] = dup(pipefds[1]);
130 if (pipefds[1] < 0) {
131 printerr(1, "mydaemon: dup() failed: errno %d (%s)\n",
132 errno, strerror(errno));
138 tempfd = open("/dev/null", O_RDWR);
152 ssize_t sret __attribute__ ((unused));
154 if (pipefds[1] > 0) {
155 sret = write(pipefds[1], &status, 1);
164 /* destroy krb5 machine creds */
166 printerr(1, "exiting on signal %d\n", signal);
173 /* don't exit on SIGHUP */
174 printerr(1, "Received SIGHUP... Ignoring.\n");
179 usage(FILE *fp, char *progname)
181 fprintf(fp, "usage: %s [ -fnvmogk ]\n",
183 fprintf(stderr, "-f - Run in foreground\n");
184 fprintf(stderr, "-n - Don't establish kerberos credentials\n");
185 fprintf(stderr, "-v - Verbosity\n");
186 fprintf(stderr, "-m - Service MDS\n");
187 fprintf(stderr, "-o - Service OSS\n");
188 fprintf(stderr, "-g - Service MGS\n");
189 fprintf(stderr, "-k - Enable kerberos support\n");
195 main(int argc, char *argv[])
201 int must_srv_mds = 0, must_srv_oss = 0, must_srv_mgs = 0;
204 while ((opt = getopt(argc, argv, "fnvmogk")) != -1) {
231 usage(stdout, argv[0]);
234 usage(stderr, argv[0]);
239 if ((progname = strrchr(argv[0], '/')))
244 initerr(progname, verbosity, fg);
246 /* For kerberos use gss mechanisms but ignore for sk and null */
247 if (krb_enabled && gssd_check_mechs() == 0) {
248 if (gssd_get_local_realm()) {
249 printerr(0, "ERROR: Can't get Local Kerberos realm\n");
254 gssd_prepare_creds(must_srv_mgs, must_srv_mds,
256 printerr(0, "unable to obtain root (machine) "
258 printerr(0, "do you have a keytab entry for "
259 "<lustre_xxs>/<your.host>@<YOUR.REALM> in "
260 "/etc/krb5.keytab?\n");
269 * XXX: There is risk of memory leak for missing call
270 * cleanup_mapping() for SIGKILL and SIGSTOP.
272 signal(SIGINT, sig_die);
273 signal(SIGTERM, sig_die);
274 signal(SIGHUP, sig_hup);
279 gssd_init_unique(GSSD_SVC);
283 printerr(0, "gssd_run returned!\n");