mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-11 19:17:22 +00:00
make ipmievd write pidfile
This commit is contained in:
parent
66ffa994e9
commit
e37e785449
@ -12,6 +12,7 @@ version 1.8.7
|
|||||||
* Add support for FreeBSD OpenIPMI-compatible driver
|
* Add support for FreeBSD OpenIPMI-compatible driver
|
||||||
* Add support for IPMIv2 Firmware Firewall
|
* Add support for IPMIv2 Firmware Firewall
|
||||||
* Fix gcc4 compile warnings
|
* Fix gcc4 compile warnings
|
||||||
|
* Make ipmievd generate pidfile
|
||||||
|
|
||||||
version 1.8.6
|
version 1.8.6
|
||||||
* Fix memory corruption when sending encrypted SOL traffic
|
* Fix memory corruption when sending encrypted SOL traffic
|
||||||
|
@ -158,6 +158,10 @@ All messages will be sent to syslog. This is the default action.
|
|||||||
.TP
|
.TP
|
||||||
\fInodaemon\fP
|
\fInodaemon\fP
|
||||||
Do NOT become a daemon, instead log all messages to stderr.
|
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
|
.RE
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
@ -176,6 +180,10 @@ All messages will be sent to syslog. This is the default action.
|
|||||||
.TP
|
.TP
|
||||||
\fInodaemon\fP
|
\fInodaemon\fP
|
||||||
Do NOT become a daemon, instead log all messages to stderr.
|
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
|
.TP
|
||||||
\fItimeout\fP=<\fBseconds\fR>
|
\fItimeout\fP=<\fBseconds\fR>
|
||||||
Time between checks for SEL polling method. Default is 10 seconds.
|
Time between checks for SEL polling method. Default is 10 seconds.
|
||||||
|
@ -40,23 +40,21 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <signal.h>
|
||||||
#ifdef __FreeBSD__
|
#include <paths.h>
|
||||||
# include <signal.h>
|
|
||||||
# include <paths.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#ifdef IPMI_INTF_OPEN
|
#ifdef IPMI_INTF_OPEN
|
||||||
# ifdef HAVE_OPENIPMI_H
|
# if defined(HAVE_OPENIPMI_H)
|
||||||
# include <linux/compiler.h>
|
# include <linux/compiler.h>
|
||||||
# include <linux/ipmi.h>
|
# include <linux/ipmi.h>
|
||||||
# include <sys/poll.h>
|
# elif defined(HAVE_FREEBSD_IPMI_H)
|
||||||
# else /* HAVE_OPENIPMI_H */
|
# include <sys/ipmi.h>
|
||||||
|
# else
|
||||||
# include "plugins/open/open.h"
|
# include "plugins/open/open.h"
|
||||||
|
# endif
|
||||||
# include <sys/poll.h>
|
# include <sys/poll.h>
|
||||||
# endif /* HAVE_OPENIPMI_H */
|
|
||||||
#endif /* IPMI_INTF_OPEN */
|
#endif /* IPMI_INTF_OPEN */
|
||||||
|
|
||||||
#include <ipmitool/helper.h>
|
#include <ipmitool/helper.h>
|
||||||
@ -68,6 +66,9 @@
|
|||||||
#include <ipmitool/ipmi_strings.h>
|
#include <ipmitool/ipmi_strings.h>
|
||||||
#include <ipmitool/ipmi_main.h>
|
#include <ipmitool/ipmi_main.h>
|
||||||
|
|
||||||
|
#define DEFAULT_PIDFILE "/var/run/ipmievd.pid"
|
||||||
|
char pidfile[64];
|
||||||
|
|
||||||
/* global variables */
|
/* global variables */
|
||||||
int verbose = 0;
|
int verbose = 0;
|
||||||
int csv_output = 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
|
int
|
||||||
ipmievd_main(struct ipmi_event_intf * eintf, int argc, char ** argv)
|
ipmievd_main(struct ipmi_event_intf * eintf, int argc, char ** argv)
|
||||||
{
|
{
|
||||||
int i, rc;
|
int i, rc;
|
||||||
int daemon = 1;
|
int daemon = 1;
|
||||||
|
struct sigaction act;
|
||||||
|
|
||||||
|
memset(pidfile, 0, 64);
|
||||||
|
strncpy(pidfile, DEFAULT_PIDFILE, strlen(DEFAULT_PIDFILE));
|
||||||
|
|
||||||
for (i = 0; i < argc; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
if (strncasecmp(argv[i], "help", 4) == 0) {
|
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) {
|
else if (strncasecmp(argv[i], "timeout=", 8) == 0) {
|
||||||
selwatch_timeout = strtoul(argv[i]+8, NULL, 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();
|
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_halt();
|
||||||
log_init("ipmievd", daemon, verbose);
|
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");
|
lprintf(LOG_DEBUG, "Sensors cached");
|
||||||
|
|
||||||
/* call event handler setup routine */
|
/* call event handler setup routine */
|
||||||
|
|
||||||
if (eintf->setup != NULL) {
|
if (eintf->setup != NULL) {
|
||||||
rc = eintf->setup(eintf);
|
rc = eintf->setup(eintf);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user