summaryrefslogtreecommitdiff
path: root/src/compat/compat-daemon.c
diff options
context:
space:
mode:
authorAlberto Gonzalez Iniesta <agi@inittab.org>2016-12-27 18:25:47 +0100
committerAlberto Gonzalez Iniesta <agi@inittab.org>2016-12-27 18:25:47 +0100
commit79f3537f69e125f19f59c36aa090120a63186a54 (patch)
tree2089a3b7dac990841dbc2e4d9b2f535b82dbb0af /src/compat/compat-daemon.c
parentf2137fedb30cb87448eb03b2f288920df6187571 (diff)
parent3a2bbdb05ca6a6996e424c9fb225cb0d53804125 (diff)
Merge tag 'upstream/2.4.0'
Upstream version 2.4.0
Diffstat (limited to 'src/compat/compat-daemon.c')
-rw-r--r--src/compat/compat-daemon.c79
1 files changed, 44 insertions, 35 deletions
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 */