From 23d828dab2107c89fbb1f93cb8263af10df01ecf Mon Sep 17 00:00:00 2001 From: William Murphy <warrendiogenese@gmail.com> Date: Thu, 7 Aug 2014 22:31:01 -0700 Subject: [PATCH] Patched patch67 --- client/msgcache.c | 23 ++++++++++++++++------- docs/manpages/man8/xymond.8.html | 3 +-- docs/manpages/man8/xymonproxy.8.html | 4 ++-- xymond/xymond.8 | 3 +-- xymond/xymond.c | 12 ++---------- xymond/xymond_history.c | 3 ++- xymonproxy/xymonproxy.8 | 4 ++-- xymonproxy/xymonproxy.c | 25 +++++++++++++++++-------- 8 files changed, 43 insertions(+), 34 deletions(-) diff --git a/client/msgcache.c b/client/msgcache.c index 7a0c116..41e7dfc 100644 --- a/client/msgcache.c +++ b/client/msgcache.c @@ -278,7 +278,7 @@ int main(int argc, char *argv[]) { int daemonize = 1; int listenq = 10; - char *pidfile = "msgcache.pid"; + char *pidfile = NULL; int lsocket; struct sockaddr_in laddr; struct sigaction sa; @@ -386,18 +386,27 @@ int main(int argc, char *argv[]) exit(1); } else if (childpid > 0) { - /* Parent - save PID and exit */ - FILE *fd = fopen(pidfile, "w"); - if (fd) { - fprintf(fd, "%d\n", (int)childpid); - fclose(fd); - } + /* Parent just exits */ exit(0); } /* Child (daemon) continues here */ setsid(); } + if (pidfile) { + /* Save PID */ + FILE *fd = fopen(pidfile, "w"); + if (fd) { + if (fprintf(fd, "%lu\n", (unsigned long)getpid()) <= 0) { + errprintf("Error writing PID file %s: %s\n", pidfile, strerror(errno)); + } + fclose(fd); + } + else { + errprintf("Cannot open PID file %s: %s\n", pidfile, strerror(errno)); + } + } + setup_signalhandler("msgcache"); memset(&sa, 0, sizeof(sa)); sa.sa_handler = sigmisc_handler; diff --git a/docs/manpages/man8/xymond.8.html b/docs/manpages/man8/xymond.8.html index 0627079..93baf0e 100644 --- a/docs/manpages/man8/xymond.8.html +++ b/docs/manpages/man8/xymond.8.html @@ -153,8 +153,7 @@ by the xymonlaunch tasks.cfg file. <P> <DT>--pidfile=FILENAME<DD> xymond writes the process-ID it is running with to this file. -This is for use in automated startup scripts. The default file is -$XYMONSERVERLOGS/xymond.pid. +This is for use in automated startup scripts. <P> <DT>--log=FILENAME<DD> Redirect all output from xymond to FILENAME. diff --git a/docs/manpages/man8/xymonproxy.8.html b/docs/manpages/man8/xymonproxy.8.html index 9b49556..db7ff08 100644 --- a/docs/manpages/man8/xymonproxy.8.html +++ b/docs/manpages/man8/xymonproxy.8.html @@ -99,8 +99,8 @@ This is the default. Runs xymonproxy as a foreground proces. <P> <DT>--pidfile=FILENAME<DD> -Specifies the location of a file containing the proces-ID -of the xymonproxy daemon proces. Default: /var/run/xymonproxy.pid. +Specifies the location of a file containing the process-ID +of the xymonproxy daemon proces. <P> <DT>--logfile=FILENAME<DD> Sends all logging output to the specified file instead of stderr. diff --git a/xymond/xymond.8 b/xymond/xymond.8 index 4f8c24e..351b021 100644 --- a/xymond/xymond.8 +++ b/xymond/xymond.8 @@ -132,8 +132,7 @@ by the xymonlaunch tasks.cfg file. .IP "--pidfile=FILENAME" xymond writes the process-ID it is running with to this file. -This is for use in automated startup scripts. The default file is -$XYMONSERVERLOGS/xymond.pid. +This is for use in automated startup scripts. .IP "--log=FILENAME" Redirect all output from xymond to FILENAME. diff --git a/xymond/xymond.c b/xymond/xymond.c index 0c9476b..2cdf5c5 100644 --- a/xymond/xymond.c +++ b/xymond/xymond.c @@ -5528,16 +5528,8 @@ int main(int argc, char *argv[]) setsid(); } - if (pidfile == NULL) { - /* Setup a default pid-file */ - char fn[PATH_MAX]; - - sprintf(fn, "%s/xymond.pid", xgetenv("XYMONSERVERLOGS")); - pidfile = strdup(fn); - } - - /* Save PID */ - { + if (pidfile != NULL) { + /* Save PID */ FILE *fd = fopen(pidfile, "w"); if (fd) { if (fprintf(fd, "%lu\n", (unsigned long)getpid()) <= 0) { diff --git a/xymond/xymond_history.c b/xymond/xymond_history.c index fc765a0..d87ba99 100644 --- a/xymond/xymond_history.c +++ b/xymond/xymond_history.c @@ -157,7 +157,8 @@ int main(int argc, char *argv[]) xfree(savelist); } - { + if (pidfn != NULL) { + /* Save PID */ FILE *pidfd = fopen(pidfn, "w"); if (pidfd) { fprintf(pidfd, "%lu\n", (unsigned long)getpid()); diff --git a/xymonproxy/xymonproxy.8 b/xymonproxy/xymonproxy.8 index 344ec47..98c75b9 100644 --- a/xymonproxy/xymonproxy.8 +++ b/xymonproxy/xymonproxy.8 @@ -79,8 +79,8 @@ This is the default. Runs xymonproxy as a foreground proces. .IP "--pidfile=FILENAME" -Specifies the location of a file containing the proces-ID -of the xymonproxy daemon proces. Default: /var/run/xymonproxy.pid. +Specifies the location of a file containing the process-ID +of the xymonproxy daemon proces. .IP "--logfile=FILENAME" Sends all logging output to the specified file instead of stderr. diff --git a/xymonproxy/xymonproxy.c b/xymonproxy/xymonproxy.c index f526ee5..772edac 100644 --- a/xymonproxy/xymonproxy.c +++ b/xymonproxy/xymonproxy.c @@ -215,7 +215,7 @@ int main(int argc, char *argv[]) int daemonize = 1; int timeout = 10; int listenq = 512; - char *pidfile = "/var/run/xymonproxy.pid"; + char *pidfile = NULL; char *proxyname = NULL; char *proxynamesvc = "xymonproxy"; @@ -340,7 +340,7 @@ int main(int argc, char *argv[]) printf("\t--lqueue=N : Listen-queue size\n"); printf("\t--daemon : Run as a daemon\n"); printf("\t--no-daemon : Do not run as a daemon\n"); - printf("\t--pidfile=FILENAME : Save proces-ID of daemon to FILENAME\n"); + printf("\t--pidfile=FILENAME : Save process-ID of daemon to FILENAME\n"); printf("\t--logfile=FILENAME : Log to FILENAME instead of stderr\n"); printf("\t--debug : Enable debugging output\n"); printf("\n"); @@ -404,18 +404,27 @@ int main(int argc, char *argv[]) exit(1); } else if (childpid > 0) { - /* Parent - save PID and exit */ - FILE *fd = fopen(pidfile, "w"); - if (fd) { - fprintf(fd, "%d\n", (int)childpid); - fclose(fd); - } + /* Parent just exits */ exit(0); } /* Child (daemon) continues here */ setsid(); } + if (pidfile) { + /* Save PID */ + FILE *fd = fopen(pidfile, "w"); + if (fd) { + if (fprintf(fd, "%lu\n", (unsigned long)getpid()) <= 0) { + errprintf("Error writing PID file %s: %s\n", pidfile, strerror(errno)); + } + fclose(fd); + } + else { + errprintf("Cannot open PID file %s: %s\n", pidfile, strerror(errno)); + } + } + setup_signalhandler(proxynamesvc); memset(&sa, 0, sizeof(sa)); sa.sa_handler = sigmisc_handler; -- 1.8.4.5