PID file patch for LambdaMOO-1.8.0p4
H. Peter Anvin (hpa@trantor.zytor.com)
Wed, 8 May 1996 20:32:02 PDT
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;
}
=20
+static const char *pid_file =3D 0;
+static void
+nuke_pid_file(void)
+{
+ if (pid_file && getpid() =3D=3D parent_pid)
+ unlink(pid_file);
+}
+
int
main(int argc, char **argv)
{
char *this_program =3D str_dup(argv[0]);
- const char *log_file =3D 0;
+ const char *log_file =3D 0;
int emergency =3D 0;
Var desc;
slistener *l;
@@ -1202,6 +1210,14 @@
} else
argc =3D 0; /* Provoke usage message below */
break;
+ case 'p': /* Specified PID file */
+ if (argc > 1) {
+ pid_file =3D argv[1];
+ argc--;
+ argv++;
+ } else
+ argc =3D 0; /* Provoke usage message below */
+ break;
default:
argc =3D 0; /* Provoke usage message below */
}
@@ -1221,9 +1237,23 @@
} else
set_log_file(stderr);
=20
+ if (pid_file) {
+ FILE *f =3D fopen(pid_file, "w");
+=09
+ 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);
}
--=20
PGP public key available - finger hpa@zytor.com
"The earth is but one country, and mankind its citizens." -- Bah=E1'u'l=
l=E1h
"One net to rule them all, one net to find them, one net to bring them al=
l
and using Unix bind them." -- Alan V. Shackelford