MOO-cows Mailing List Archive

[Prev][Next][Index][Thread]

PID file patch for LambdaMOO-1.8.0p4



A very small patch for LambdaMOO-1.8.0p4 which enables writing a file
containing the process ID of the LambdaMOO process.  The process ID is
needed to send signals, e.g.

	kill -TERM `cat MyMOO.pid`	(shutdown)
	kill -USR2 `cat MyMOO.pid`	(checkpoint)

To write a pid file, start the MOO with:

	moo -p MyMOO.pid MyMOO.db MyMOO.db.new 8888

or add the equivalent to the restart script.

	-hpa


--- server.c.dist	Wed May  8 19:58:40 1996
+++ server.c	Wed May  8 20:25:02 1996
@@ -1175,11 +1175,19 @@
     return 1;
 }
 
+static const char      *pid_file = 0;
+static void
+nuke_pid_file(void)
+{
+    if (pid_file && getpid() == parent_pid)
+        unlink(pid_file);
+}
+
 int
 main(int argc, char **argv)
 {
     char       	       *this_program = str_dup(argv[0]);
-    const char	       *log_file = 0;
+    const char         *log_file = 0;
     int			emergency = 0;
     Var			desc;
     slistener	       *l;
@@ -1202,6 +1210,14 @@
 	    } else
 		argc = 0;	/* Provoke usage message below */
 	    break;
+	  case 'p':		/* Specified PID file */
+	    if (argc > 1) {
+	        pid_file = argv[1];
+		argc--;
+		argv++;
+	    } else
+	        argc = 0;	/* Provoke usage message below */
+	    break;
 	  default:
 	    argc = 0;		/* Provoke usage message below */
 	}
@@ -1221,9 +1237,23 @@
     } else
 	set_log_file(stderr);
 
+    if (pid_file) {
+        FILE *f = fopen(pid_file, "w");
+	
+	if (f) {
+	    /* Note: pid_t differs between systems, so play it safe */
+	    fprintf(f, "%lu\n", (unsigned long) getpid());
+	    fclose(f);
+	    atexit(nuke_pid_file);
+	} else {
+	    perror("Error creating specified pid file");
+	    exit(1);
+	}
+    }
+
     if (!db_initialize(&argc, &argv)
 	||  !network_initialize(argc, argv, &desc)) {
-	fprintf(stderr, "Usage: %s [-e] [-l log-file] %s %s\n",
+	fprintf(stderr, "Usage: %s [-e] [-l log-file] [-p pid-file] %s %s\n",
 		this_program, db_usage_string(), network_usage_string());
 	exit(1);
     }

-- 
PGP public key available - finger hpa@zytor.com
"The earth is but one country, and mankind its citizens."  --  Bahá'u'lláh
"One net to rule them all, one net to find them, one net to bring them all
and using Unix bind them."  -- Alan V. Shackelford


Follow-Ups:

Home | Subject Index | Thread Index