[11669] in Athena Bugs
zhm shouldn't kill old zhm process
daemon@ATHENA.MIT.EDU (Jonathan I. Kamens)
Wed Jan 26 19:10:50 1994
Date: Wed, 26 Jan 1994 19:11:53 -0500
From: "Jonathan I. Kamens" <jik@security.ov.com>
To: bugs@MIT.EDU
The most common cause of zhm starting up when there's an
existing /etc/zhm.pid file is during a reboot. In such a situation,
it's quite possible that the PID recorded in /etc/zhm.pid file (which
was created by the zhm that crashed as a result of the reboot) now
belongs to another process.
Therefore, it seems to me that zhm shouldn't try to kill any
process running with the PID given in /etc/zhm.pid, especially since
it's running as root.
Far better behavior, I think, would be for it to send a 0
signal to the process listed in the /etc/zhm.pid file and, if it
succeeds (i.e., if the process exists), to print an error to stderr,
log an error with syslog, and exit. Such a situation is more safely
remedied by hand than by zhm sending a TERM signal to a process that
may not actually be a zhm process.
Here's a patch (which is based on the patch I sent in recently
to prevent zhm from killing lots of processes of the PidFile is
empty):
*** zhm.c 1994/01/16 19:42:21 1.51
--- zhm.c 1994/01/27 00:10:51
***************
*** 323,332 ****
/* kill old hm if it exists */
fp = fopen(PidFile, "r");
if (fp != NULL) {
! if (fscanf(fp, "%d\n", &oldpid) > 0) {
! while (!kill(oldpid, SIGTERM))
! sleep(1);
! syslog(LOG_INFO, "Killed old image.");
}
(void) fclose(fp);
}
--- 323,337 ----
/* kill old hm if it exists */
fp = fopen(PidFile, "r");
if (fp != NULL) {
! if ((fscanf(fp, "%d\n", &oldpid) > 0) &&
! (! kill(oldpid, 0))) {
! fprintf(stderr,
! "%s: Process listed in %s (%d) is running. If it is a zhm process, then\nyou should kill it by hand and start zhm again.\n",
! PidFile, oldpid);
! syslog(LOG_ERR,
! "Process listed in %s (%d) is running. Exiting.",
! PidFile, oldpid);
! exit(1);
}
(void) fclose(fp);
}
Jonathan Kamens | OpenVision Technologies, Inc. | jik@security.ov.com