Skip to content

Commit ec63289

Browse files
Marc TeitelbaumMarc Teitelbaum
Marc Teitelbaum
authored and
Marc Teitelbaum
committed
date and time created 90/06/15 14:47:14 by marc
SCCS-vsn: lib/libc/gen/daemon.c 5.1
1 parent 91d68bd commit ec63289

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

‎usr/src/lib/libc/gen/daemon.c

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*-
2+
* Copyright (c) 1990 The Regents of the University of California.
3+
* All rights reserved.
4+
*
5+
* %sccs.include.redist.c%
6+
*/
7+
8+
#if defined(LIBC_SCCS) && !defined(lint)
9+
static char sccsid[] = "@(#)daemon.c 5.1 (Berkeley) %G%";
10+
#endif /* LIBC_SCCS and not lint */
11+
12+
#include <sys/file.h>
13+
14+
daemon()
15+
{
16+
int cpid;
17+
18+
if ((cpid = fork()) == -1)
19+
return (-1);
20+
if (cpid)
21+
exit(0);
22+
23+
(void) setsid();
24+
(void) chdir("/");
25+
(void) close(0);
26+
(void) close(1);
27+
(void) close(2);
28+
(void) open("/", O_RDONLY, 0);
29+
(void) dup2(0, 1);
30+
(void) dup2(0, 2);
31+
}

0 commit comments

Comments
 (0)