+ note (N_FATAL, "Caught signal %d, un-registering and exiting.", sig);
+ if (!(run_mode & MODE_NOTIFY_ONLY))
+ pmap_unset (SM_PROG, SM_VERS);
+
+ exit (0);
+}
+
+static void
+sigusr (int sig)
+{
+ dprintf (N_DEBUG, "Caught signal %d, re-notifying (state %d).", sig,
+ MY_STATE);
+ re_notify = 1;
+}
+
+/*
+ * Startup information.
+ */
+static void log_modes(void)
+{
+ char buf[128]; /* watch stack size... */
+
+ /* No flags = no message */
+ if (!run_mode) return;
+
+ memset(buf,0,128);
+ sprintf(buf,"Flags: ");
+ if (run_mode & MODE_NODAEMON)
+ strcat(buf,"No-Daemon ");
+ if (run_mode & MODE_LOG_STDERR)
+ strcat(buf,"Log-STDERR ");
+
+ if (run_mode & MODE_NOTIFY_ONLY)
+ {
+ strcat(buf,"Notify-Only ");
+ }
+ note(N_WARNING,buf);
+ /* future: IP aliasing
+ if (run_mode & MODE_NOTIFY_ONLY)
+ {
+ dprintf(N_DEBUG,"Notify IP: %s",svr_addr);
+ } */
+}
+
+/*
+ * Since we do more than standard statd stuff, we might need to
+ * help the occasional admin.
+ */
+static void
+usage()
+{
+ fprintf(stderr,"usage: %s [options]\n", name_p);
+ fprintf(stderr," -h, -?, --help Print this help screen.\n");
+ fprintf(stderr," -F, --foreground Foreground (no-daemon mode)\n");
+ fprintf(stderr," -d, --no-syslog Verbose logging to stderr. Foreground mode only.\n");
+ fprintf(stderr," -p, --port Port to listen on\n");
+ fprintf(stderr," -o, --outgoing-port Port for outgoing connections\n");
+ fprintf(stderr," -V, -v, --version Display version information and exit.\n");
+ fprintf(stderr," -n, --name Specify a local hostname.\n");
+ fprintf(stderr," -P State directory path.\n");
+ fprintf(stderr," -N Run in notify only mode.\n");
+ fprintf(stderr," -H Specify a high-availability callout program.\n");
+}
+
+static const char *pidfile = "/var/run/rpc.statd.pid";
+
+int pidfd = -1;
+static void create_pidfile(void)
+{
+ FILE *fp;
+
+ unlink(pidfile);
+ fp = fopen(pidfile, "w");
+ if (!fp)
+ die("Opening %s failed: %s\n",
+ pidfile, strerror(errno));
+ fprintf(fp, "%d\n", getpid());
+ pidfd = dup(fileno(fp));
+ if (fclose(fp) < 0)
+ note(N_WARNING, "Flushing pid file failed.\n");