+ statd_unregister ();
+ xlog_err ("Caught signal %d, un-registering and exiting", sig);
+}
+
+static void
+sigusr (int sig)
+{
+ extern void my_svc_exit (void);
+ xlog(D_GENERAL, "Caught signal %d, re-notifying (state %d)", sig,
+ MY_STATE);
+ my_svc_exit();
+}
+
+/*
+ * 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 ");
+#ifdef HAVE_LIBTIRPC
+ strcat(buf, "TI-RPC ");
+#endif
+
+ xlog_warn(buf);
+}
+
+/*
+ * Since we do more than standard statd stuff, we might need to
+ * help the occasional admin.
+ */
+static void
+usage(void)
+{
+ 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," -L, --no-notify Do not perform any notification.\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)
+ xlog_err("Opening %s failed: %m\n", pidfile);
+ fprintf(fp, "%d\n", getpid());
+ pidfd = dup(fileno(fp));
+ if (fclose(fp) < 0) {
+ xlog_warn("Flushing pid file failed: errno %d (%m)\n",
+ errno);
+ }