2 * Copyright (C) 1995, 1997-1999 Jeffrey A. Uphoff
3 * Modified by Olaf Kirch, Oct. 1996.
4 * Modified by H.J. Lu, 1998.
5 * Modified by L. Hohberger of Mission Critical Linux, 2000.
16 #include <rpc/pmap_clnt.h>
20 /* Socket operations */
21 #include <sys/types.h>
22 #include <sys/socket.h>
25 short int restart = 0;
26 int _rpcpmstart = 0; /* flags for tirpc rpcgen */
29 int run_mode = 0; /* foreground logging mode */
31 /* LH - I had these local to main, but it seemed silly to have
32 * two copies of each - one in main(), one static in log.c...
33 * It also eliminates the 256-char static in log.c */
35 char *version_p = NULL;
37 extern void sm_prog_1 (struct svc_req *, register SVCXPRT *);
40 extern void simulator (int, char **);
44 #ifdef HAVE_TCP_WRAPPER
45 #include "tcpwrapper.h"
48 sm_prog_1_wrapper (struct svc_req *rqstp, register SVCXPRT *transp)
50 /* remote host authorization check */
51 if (!check_default("statd", svc_getcaller(transp),
52 rqstp->rq_proc, SM_PROG)) {
53 svcerr_auth (transp, AUTH_FAILED);
57 sm_prog_1 (rqstp, transp);
60 #define sm_prog_1 sm_prog_1_wrapper
69 log (L_FATAL, "Caught signal %d, un-registering and exiting.", sig);
70 pmap_unset (SM_PROG, SM_VERS);
75 * Startup information.
77 static void log_modes(void)
79 char buf[128]; /* watch stack size... */
81 /* No flags = no message */
82 if (!run_mode) return;
85 sprintf(buf,"Flags: ");
86 if (run_mode & MODE_NODAEMON)
87 strcat(buf,"No-Daemon ");
88 if (run_mode & MODE_LOG_STDERR)
89 strcat(buf,"Log-STDERR ");
90 /* future: IP aliasing
91 if (run_mode & MODE_NOTIFY_ONLY)
93 strcat(buf,"Notify-Only ");
96 /* future: IP aliasing
97 if (run_mode & MODE_NOTIFY_ONLY)
99 dprintf(L_DEBUG,"Notify IP: %s",svr_addr);
104 * Since we do more than standard statd stuff, we might need to
105 * help the occasional admin.
110 fprintf(stderr,"usage: %s [options]\n", name_p);
111 fprintf(stderr," -h, -? Print this help screen.\n");
112 fprintf(stderr," -F Foreground (no-daemon mode)\n");
113 fprintf(stderr," -d Verbose logging to stderr. Foreground mode only.\n");
114 fprintf(stderr," -V Display version information and exit.\n");
118 * Entry routine/main loop.
120 int main (int argc, char **argv)
126 /* Default: daemon mode, no other options */
129 /* Set the basename */
130 if ((name_p = strrchr(argv[0],'/')) != NULL) {
136 /* Get the version */
137 if ((version_p = strrchr(VERSION,' ')) != NULL) {
143 /* Process command line switches */
144 while ((arg = getopt(argc, argv, "h?VFd")) >= 0) {
146 case 'V': /* Version */
147 printf("%s version %s\n",name_p,version_p);
149 case 'F': /* Foreground/nodaemon mode */
150 run_mode |= MODE_NODAEMON;
152 case 'd': /* No daemon only - log to stderr */
153 run_mode |= MODE_LOG_STDERR;
155 case '?': /* heeeeeelllllllpppp? heh */
159 default: /* oh dear ... heh */
165 if (!(run_mode & MODE_NODAEMON)) {
166 run_mode &= ~MODE_LOG_STDERR; /* Never log to console in
170 log_init (name_p,version_p);
176 /* LH - I _really_ need to update simulator... */
177 simulator (--argc, ++argv); /* simulator() does exit() */
180 if (!(run_mode & MODE_NODAEMON)) {
183 if ((pid = fork ()) < 0) {
184 perror ("Could not fork");
186 } else if (pid != 0) {
194 for (filedes = 0; filedes < sysconf (_SC_OPEN_MAX); filedes++) {
200 signal (SIGHUP, killer);
201 signal (SIGINT, killer);
202 signal (SIGTERM, killer);
203 /* WARNING: the following works on Linux and SysV, but not BSD! */
204 signal(SIGCHLD, SIG_IGN);
207 pmap_unset (SM_PROG, SM_VERS);
209 shuffle_dirs (); /* Move directory names around */
210 notify_hosts (); /* Send out notify requests */
213 /* future: IP aliasing
214 if (!(run_mode & MODE_NOTIFY_ONLY)) {
215 do_regist (SM_PROG, sm_prog_1);
217 do_regist(SM_PROG,sm_prog_1);
220 * Handle incoming requests: SM_NOTIFY socket requests, as
221 * well as callbacks from lockd.
223 my_svc_run(); /* I rolled my own, Olaf made it better... */
232 void do_regist(u_long prog, void (*sm_prog_1)())
236 if ((transp = svcudp_create(RPC_ANYSOCK)) == NULL)
237 die("cannot create udp service.");
239 if (!svc_register(transp, prog, SM_VERS, sm_prog_1, IPPROTO_UDP))
240 die("unable to register (SM_PROG, SM_VERS, udp).");
242 if ((transp = svctcp_create(RPC_ANYSOCK, 0, 0)) == NULL)
243 die("cannot create tcp service.");
245 if (!svc_register(transp, prog, SM_VERS, sm_prog_1, IPPROTO_TCP))
246 die("unable to register (SM_PROG, SM_VERS, tcp).");