git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@3581 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
1997-10-04 21:55:48 +00:00
parent aca425f0e9
commit c0896c4709

View File

@@ -56,34 +56,33 @@ RCSID("$Id$");
#include "roken.h" #include "roken.h"
int int
daemon(nochdir, noclose) daemon(int nochdir, int noclose)
int nochdir, noclose;
{ {
int fd; int fd;
switch (fork()) { switch (fork()) {
case -1: case -1:
return (-1); return (-1);
case 0: case 0:
break; break;
default: default:
_exit(0); _exit(0);
} }
if (setsid() == -1) if (setsid() == -1)
return (-1); return (-1);
if (!nochdir) if (!nochdir)
(void)chdir("/"); chdir("/");
if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
(void)dup2(fd, STDIN_FILENO); dup2(fd, STDIN_FILENO);
(void)dup2(fd, STDOUT_FILENO); dup2(fd, STDOUT_FILENO);
(void)dup2(fd, STDERR_FILENO); dup2(fd, STDERR_FILENO);
if (fd > 2) if (fd > 2)
(void)close (fd); close (fd);
} }
return (0); return (0);
} }
#endif /* HAVE_DAEMON */ #endif /* HAVE_DAEMON */