2 * Copyright 2007, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Axel Dörfler, axeld@pinc-software.de
16 restore_old_sighup(int result
, struct sigaction
*action
)
19 sigaction(SIGHUP
, action
, NULL
);
24 daemon(int noChangeDir
, int noClose
)
26 struct sigaction oldAction
, action
;
31 /* Ignore eventually send SIGHUPS on parent exit */
32 sigemptyset(&action
.sa_mask
);
33 action
.sa_handler
= SIG_IGN
;
35 oldActionResult
= sigaction(SIGHUP
, &action
, &oldAction
);
39 restore_old_sighup(oldActionResult
, &oldAction
);
43 // we're the parent - let's exit
48 restore_old_sighup(oldActionResult
, &oldAction
);
57 int fd
= open("/dev/null", O_RDWR
);
59 dup2(fd
, STDIN_FILENO
);
60 dup2(fd
, STDOUT_FILENO
);
61 dup2(fd
, STDERR_FILENO
);
62 if (fd
> STDERR_FILENO
)