make ipmievd write pidfile

This commit is contained in:
Duncan Laurie 2006-03-19 22:35:12 +00:00
parent 66ffa994e9
commit e37e785449
3 changed files with 68 additions and 10 deletions

View File

@ -12,6 +12,7 @@ version 1.8.7
* Add support for FreeBSD OpenIPMI-compatible driver
* Add support for IPMIv2 Firmware Firewall
* Fix gcc4 compile warnings
* Make ipmievd generate pidfile
version 1.8.6
* Fix memory corruption when sending encrypted SOL traffic

View File

@ -158,6 +158,10 @@ All messages will be sent to syslog. This is the default action.
.TP
\fInodaemon\fP
Do NOT become a daemon, instead log all messages to stderr.
.TP
\fIpidfile\fP=<\fBfilename\fR>
Save process ID to this file when in daemon mode. Defaults to
/var/run/ipmievd.pid.
.RE
.TP
@ -176,6 +180,10 @@ All messages will be sent to syslog. This is the default action.
.TP
\fInodaemon\fP
Do NOT become a daemon, instead log all messages to stderr.
.TP
\fIpidfile\fP=<\fBfilename\fR>
Save process ID to this file when in daemon mode. Defaults to
/var/run/ipmievd.pid.
.TP
\fItimeout\fP=<\fBseconds\fR>
Time between checks for SEL polling method. Default is 10 seconds.

View File

@ -40,23 +40,21 @@
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef __FreeBSD__
# include <signal.h>
# include <paths.h>
#endif
#include <signal.h>
#include <paths.h>
#include <config.h>
#ifdef IPMI_INTF_OPEN
# ifdef HAVE_OPENIPMI_H
# if defined(HAVE_OPENIPMI_H)
# include <linux/compiler.h>
# include <linux/ipmi.h>
# include <sys/poll.h>
# else /* HAVE_OPENIPMI_H */
# elif defined(HAVE_FREEBSD_IPMI_H)
# include <sys/ipmi.h>
# else
# include "plugins/open/open.h"
# endif
# include <sys/poll.h>
# endif /* HAVE_OPENIPMI_H */
#endif /* IPMI_INTF_OPEN */
#include <ipmitool/helper.h>
@ -68,6 +66,9 @@
#include <ipmitool/ipmi_strings.h>
#include <ipmitool/ipmi_main.h>
#define DEFAULT_PIDFILE "/var/run/ipmievd.pid"
char pidfile[64];
/* global variables */
int verbose = 0;
int csv_output = 0;
@ -580,11 +581,28 @@ selwatch_wait(struct ipmi_event_intf * eintf)
}
/*************************************************************************/
static void
ipmievd_cleanup(int signal)
{
struct stat st1;
if (lstat(pidfile, &st1) == 0) {
/* cleanup daemon pidfile */
(void)unlink(pidfile);
}
exit(EXIT_SUCCESS);
}
int
ipmievd_main(struct ipmi_event_intf * eintf, int argc, char ** argv)
{
int i, rc;
int daemon = 1;
struct sigaction act;
memset(pidfile, 0, 64);
strncpy(pidfile, DEFAULT_PIDFILE, strlen(DEFAULT_PIDFILE));
for (i = 0; i < argc; i++) {
if (strncasecmp(argv[i], "help", 4) == 0) {
@ -608,11 +626,41 @@ ipmievd_main(struct ipmi_event_intf * eintf, int argc, char ** argv)
else if (strncasecmp(argv[i], "timeout=", 8) == 0) {
selwatch_timeout = strtoul(argv[i]+8, NULL, 0);
}
else if (strncasecmp(argv[i], "pidfile=", 8) == 0) {
memset(pidfile, 0, 64);
strncpy(pidfile, argv[i]+8,
__min(strlen((const char *)(argv[i]+8)), 63));
}
}
if (daemon)
if (daemon) {
FILE *fp;
struct stat st1;
ipmi_start_daemon();
if (lstat(pidfile, &st1) == 0) {
/* already exists, erase first */
if (unlink(pidfile) != 0) {
lprintf(LOG_WARN, "Unable to erase pidfile");
}
}
fp = ipmi_open_file_write(pidfile);
if (fp != NULL) {
fprintf(fp, "%d\n", (int)getpid());
fclose(fp);
}
}
/* register signal handler for cleanup */
act.sa_handler = ipmievd_cleanup;
act.sa_flags = 0;
sigemptyset(&act.sa_mask);
sigaction(SIGINT, &act, NULL);
sigaction(SIGQUIT, &act, NULL);
sigaction(SIGTERM, &act, NULL);
log_halt();
log_init("ipmievd", daemon, verbose);
@ -622,6 +670,7 @@ ipmievd_main(struct ipmi_event_intf * eintf, int argc, char ** argv)
lprintf(LOG_DEBUG, "Sensors cached");
/* call event handler setup routine */
if (eintf->setup != NULL) {
rc = eintf->setup(eintf);
if (rc < 0) {