Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
date and time created 90/06/15 14:47:14 by marc
SCCS-vsn: lib/libc/gen/daemon.c 5.1
- Loading branch information
Marc Teitelbaum
authored and
Marc Teitelbaum
committed
Jun 16, 1990
1 parent
91d68bd
commit ec63289
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/*- | ||
* Copyright (c) 1990 The Regents of the University of California. | ||
* All rights reserved. | ||
* | ||
* %sccs.include.redist.c% | ||
*/ | ||
|
||
#if defined(LIBC_SCCS) && !defined(lint) | ||
static char sccsid[] = "@(#)daemon.c 5.1 (Berkeley) %G%"; | ||
#endif /* LIBC_SCCS and not lint */ | ||
|
||
#include <sys/file.h> | ||
|
||
daemon() | ||
{ | ||
int cpid; | ||
|
||
if ((cpid = fork()) == -1) | ||
return (-1); | ||
if (cpid) | ||
exit(0); | ||
|
||
(void) setsid(); | ||
(void) chdir("/"); | ||
(void) close(0); | ||
(void) close(1); | ||
(void) close(2); | ||
(void) open("/", O_RDONLY, 0); | ||
(void) dup2(0, 1); | ||
(void) dup2(0, 2); | ||
} |