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
commit3a2bbdb05ca6a6996e424c9fb225cb0d53804125 (patch)
treef29063da5bec4caf3853d49a22a09c8619eebd21 /src/compat/compat-daemon.c
parentd53dba59e78da865c4fe820386ff2f4f76925f3b (diff)
New upstream version 2.4.0upstream/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 */