X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrd_daemon.c;h=0816526bd43a808e549dc4c68b1b4f04aa7dbf82;hb=cf698f50df236066f2b098e8aae7dafae8ba4378;hp=0fd0fabc82ec596f6ccdefbc2cb375858b7e8969;hpb=11025bcccff1b3cfe42e06cbcec425ef796ec35d;p=rrdtool.git diff --git a/src/rrd_daemon.c b/src/rrd_daemon.c index 0fd0fab..0816526 100644 --- a/src/rrd_daemon.c +++ b/src/rrd_daemon.c @@ -1,6 +1,7 @@ /** * RRDTool - src/rrd_daemon.c * Copyright (C) 2008 Florian octo Forster + * Copyright (C) 2008 Kevin Brintnall * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -20,6 +21,30 @@ * kevin brintnall **/ +#if 0 +/* + * First tell the compiler to stick to the C99 and POSIX standards as close as + * possible. + */ +#ifndef __STRICT_ANSI__ /* {{{ */ +# define __STRICT_ANSI__ +#endif + +#ifndef _ISOC99_SOURCE +# define _ISOC99_SOURCE +#endif + +#ifdef _POSIX_C_SOURCE +# undef _POSIX_C_SOURCE +#endif +#define _POSIX_C_SOURCE 200112L + +/* Single UNIX needed for strdup. */ +#ifdef _XOPEN_SOURCE +# undef _XOPEN_SOURCE +#endif +#define _XOPEN_SOURCE 500 + #ifndef _REENTRANT # define _REENTRANT #endif @@ -28,7 +53,11 @@ # define _THREAD_SAFE #endif +#ifdef _GNU_SOURCE +# undef _GNU_SOURCE +#endif /* }}} */ +#endif /* 0 */ /* * Now for some includes.. @@ -1754,9 +1783,7 @@ static void *listen_thread_main (void *args __attribute__((unused))) /* {{{ */ static int daemonize (void) /* {{{ */ { - pid_t child; int status; - char *base_dir; /* These structures are static, because `sigaction' behaves weird if the are * overwritten.. */ @@ -1764,44 +1791,46 @@ static int daemonize (void) /* {{{ */ static struct sigaction sa_term; static struct sigaction sa_pipe; - if (stay_foreground) - goto child_startup; - - child = fork (); - if (child < 0) + if (!stay_foreground) { - fprintf (stderr, "daemonize: fork(2) failed.\n"); - return (-1); - } - else if (child > 0) - { - return (1); - } + pid_t child; + char *base_dir; - /* Change into the /tmp directory. */ - base_dir = (config_base_dir != NULL) - ? config_base_dir - : "/tmp"; - status = chdir (base_dir); - if (status != 0) - { - fprintf (stderr, "daemonize: chdir (%s) failed.\n", base_dir); - return (-1); - } + child = fork (); + if (child < 0) + { + fprintf (stderr, "daemonize: fork(2) failed.\n"); + return (-1); + } + else if (child > 0) + { + return (1); + } + + /* Change into the /tmp directory. */ + base_dir = (config_base_dir != NULL) + ? config_base_dir + : "/tmp"; + status = chdir (base_dir); + if (status != 0) + { + fprintf (stderr, "daemonize: chdir (%s) failed.\n", base_dir); + return (-1); + } - /* Become session leader */ - setsid (); + /* Become session leader */ + setsid (); - /* Open the first three file descriptors to /dev/null */ - close (2); - close (1); - close (0); + /* Open the first three file descriptors to /dev/null */ + close (2); + close (1); + close (0); - open ("/dev/null", O_RDWR); - dup (0); - dup (0); + open ("/dev/null", O_RDWR); + dup (0); + dup (0); + } /* if (!stay_foreground) */ -child_startup: /* Install signal handlers */ memset (&sa_int, 0, sizeof (sa_int)); sa_int.sa_handler = sig_int_handler;