Signed-off-by: Sven Eckelmann <[email protected]>
---
posix/init.c | 45 ++-------------------------------------------
1 file changed, 2 insertions(+), 43 deletions(-)
diff --git a/posix/init.c b/posix/init.c
index 308e476..3bc54b0 100644
--- a/posix/init.c
+++ b/posix/init.c
@@ -35,6 +35,7 @@
#include <arpa/inet.h>
#include <fcntl.h>
#include <getopt.h>
+#include <unistd.h>
#include "../os.h"
@@ -44,48 +45,6 @@
int8_t stop;
-
-static int my_daemon(void) {
-
- int fd;
-
- switch( fork() ) {
-
- case -1:
- return -1;
-
- case 0:
- break;
-
- default:
- exit(EXIT_SUCCESS);
-
- }
-
- if ( setsid() == -1 )
- return(-1);
-
- /* Make certain we are not a session leader, or else we might reacquire
a controlling terminal */
- if ( fork() )
- exit(EXIT_SUCCESS);
-
- chdir( "/" );
-
- if ( ( fd = open(_PATH_DEVNULL, O_RDWR, 0) ) != -1 ) {
-
- dup2(fd, STDIN_FILENO);
- dup2(fd, STDOUT_FILENO);
- dup2(fd, STDERR_FILENO);
-
- if ( fd > 2 )
- close(fd);
-
- }
-
- return 0;
-
-}
-
static void create_routing_pipe(void)
{
int fd[2], pipe_opts;
@@ -534,7 +493,7 @@ void apply_init_args( int argc, char *argv[] ) {
/* daemonize */
if (debug_level == 0) {
- if (my_daemon() < 0) {
+ if (daemon(0, 0) < 0) {
printf("Error - can't fork to background:
%s\n", strerror(errno));
restore_defaults();
--
1.8.4.rc3