From 3a2bbdb05ca6a6996e424c9fb225cb0d53804125 Mon Sep 17 00:00:00 2001 From: Alberto Gonzalez Iniesta Date: Tue, 27 Dec 2016 18:25:47 +0100 Subject: New upstream version 2.4.0 --- src/compat/compat-daemon.c | 79 ++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 35 deletions(-) (limited to 'src/compat/compat-daemon.c') diff --git a/src/compat/compat-daemon.c b/src/compat/compat-daemon.c index dde96a2..5093942 100644 --- a/src/compat/compat-daemon.c +++ b/src/compat/compat-daemon.c @@ -58,43 +58,52 @@ int daemon(int nochdir, int noclose) { #if defined(HAVE_FORK) && defined(HAVE_SETSID) - switch (fork()) { - case -1: - return (-1); - case 0: - break; - default: - exit(0); - } - - if (setsid() == -1) - return (-1); - - if (!nochdir) - chdir("/"); - - if (!noclose) { + switch (fork()) { + case -1: + return (-1); + + case 0: + break; + + default: + exit(0); + } + + if (setsid() == -1) + { + return (-1); + } + + if (!nochdir) + { + chdir("/"); + } + + if (!noclose) + { #if defined(HAVE_DUP) && defined(HAVE_DUP2) - int fd; - if ((fd = open ("/dev/null", O_RDWR, 0)) != -1) { - dup2 (fd, 0); - dup2 (fd, 1); - dup2 (fd, 2); - if (fd > 2) { - close (fd); - } - } -#endif - } - - return 0; -#else - (void)nochdir; - (void)noclose; - errno = EFAULT; - return -1; + int fd; + if ((fd = open("/dev/null", O_RDWR, 0)) != -1) + { + dup2(fd, 0); + dup2(fd, 1); + dup2(fd, 2); + if (fd > 2) + { + close(fd); + } + } #endif + } + + return 0; +#else /* if defined(HAVE_FORK) && defined(HAVE_SETSID) */ + (void)nochdir; + (void)noclose; + errno = EFAULT; + return -1; +#endif /* if defined(HAVE_FORK) && defined(HAVE_SETSID) */ } -#endif +#endif /* ifndef HAVE_DAEMON */ -- cgit v1.2.3