123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #include "common.h"
- #ifndef HAVE_DAEMON
- #if defined(LIBC_SCCS) && !defined(lint)
- static char rcsid[] = "$OpenBSD: daemon.c,v 1.5 2003/07/15 17:32:41 deraadt Exp $";
- #endif
- int
- daemon(int nochdir, int noclose)
- {
- int fd;
- switch (fork()) {
- case -1:
- return (-1);
- case 0:
- #ifdef HAVE_CYGWIN
- register_9x_service();
- #endif
- break;
- default:
- #ifdef HAVE_CYGWIN
-
- sleep(1);
- #endif
- _exit(0);
- }
- if (setsid() == -1)
- return (-1);
- if (!nochdir)
- (void)chdir("/");
- if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
- (void)dup2(fd, STDIN_FILENO);
- (void)dup2(fd, STDOUT_FILENO);
- (void)dup2(fd, STDERR_FILENO);
- if (fd > 2)
- (void)close (fd);
- }
- return (0);
- }
- #endif
|