From 7869df43d6fd88ece4de7d0672e4e590767cf1fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sat, 4 Jun 2016 23:20:38 +0200 Subject: Imported Upstream version 1.0 --- downtimed.c | 51 ++++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) (limited to 'downtimed.c') diff --git a/downtimed.c b/downtimed.c index cb3901a..9314091 100644 --- a/downtimed.c +++ b/downtimed.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009-2013 EPIPE Communications. All rights reserved. + * Copyright (c) 2009-2016 Janne Snabb. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -22,16 +22,10 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * The views and conclusions contained in the software and documentation are - * those of the authors and should not be interpreted as representing official - * policies, either expressed or implied, of EPIPE Communications. - * * * Software web site: - * http://dist.epipe.com/downtimed/ + * https://dist.epipe.com/downtimed/ * - * Author contact information: - * opensource@epipe.com */ /* Include config.h in case we use autoconf. */ @@ -150,6 +144,7 @@ static int daemon(int, int); /* Command line arguments with their defaults */ static char * cf_log = "daemon"; /* syslog facility or filename with / */ +static int cf_fork = 1; /* whether to call daemon() which fork()s */ static char * cf_pidfile = _PATH_VARRUN PROGNAME ".pid"; static char * cf_datadir = PATH_DOWNTIMEDBDIR; static long cf_sleep = 15; /* update time stamp every 15 seconds */ @@ -225,13 +220,13 @@ main(int argc, char *argv[]) errx(EX_OSERR, "asprintf failed, out of memory?"); } -#ifndef __APPLE__ /* under Mac OS X, use launchd(8) */ - /* run as daemon (fork and detach from controlling tty) */ - if (daemon(0, 0) < 0) { - logwr(LOG_CRIT, "starting daemon failed: %s", strerror(errno)); - err(EX_OSERR, "starting daemon failed"); + if (cf_fork) { + /* run as daemon (fork and detach from controlling tty) */ + if (daemon(0, 0) < 0) { + logwr(LOG_CRIT, "starting daemon failed: %s", strerror(errno)); + err(EX_OSERR, "starting daemon failed"); + } } -#endif /* create pid file */ if (makepidfile() < 0) { @@ -695,8 +690,8 @@ static void usage() { - fputs("usage: " PROGNAME " [-DvS] [-d datadir] [-l log] [-p pidfile] " - "[-s sleep]\n", stderr); + fputs("usage: " PROGNAME " [-DFvS] [-d datadir] [-f timefmt] " + "[-l log] [-p pidfile] [-s sleep]\n", stderr); exit(EX_USAGE); } @@ -708,13 +703,12 @@ version() puts(PROGNAME " " PROGVERSION " - system downtime reporting daemon\n"); - puts("Copyright (c) 2009-2013 EPIPE Communications. " + puts("Copyright (c) 2009-2016 Janne Snabb. " "All rights reserved."); - puts("This software is licensed under the terms and conditions of the " - "FreeBSD"); - puts("License which is also known as the Simplified BSD License. You " - "should have "); - puts("received a copy of that license along with this software.\n"); + + puts("This software is licensed under the terms and conditions of the"); + puts("Simplified BSD License. You should have received a copy of that"); + puts("license along with this software.\n"); puts("Default settings:"); printf(" log = %s\n", cf_log); @@ -725,6 +719,7 @@ version() #ifdef HAVE_FUTIMES printf(" fsync = %d\n", cf_fsync); #endif + printf(" timefmt = %s\n", cf_timefmt); #ifdef PACKAGE_URL puts("\nSee the following web site for more information and updates:"); @@ -741,7 +736,7 @@ parseargs(int argc, char *argv[]) int c; char *p; - while ((c = getopt(argc, argv, "Dd:f:l:p:s:Svh?")) != -1) { + while ((c = getopt(argc, argv, "Dd:Ff:l:p:s:Svh?")) != -1) { switch (c) { case 'D': cf_downtimedb = 0; @@ -749,6 +744,9 @@ parseargs(int argc, char *argv[]) case 'd': cf_datadir = optarg; break; + case 'F': + cf_fork = 0; + break; case 'f': cf_timefmt = optarg; break; @@ -798,6 +796,10 @@ makepidfile() struct stat sb, sb2; int fd; + if (strcmp(cf_pidfile, "none") == 0) { + return (0); + } + retry: if ((fd = open(cf_pidfile, O_WRONLY | O_CREAT, DEFFILEMODE)) < 0) { logwr(LOG_ERR, "can not open pid file %s: %s", @@ -863,6 +865,9 @@ retry: static void removepidfile() { + if (strcmp(cf_pidfile, "none") == 0) { + return; + } /* * We are not releasing the lock. We still have an open -- cgit v1.2.3