[commits] [batmand] master: Use POSIX daemon function instead of self-written one (e22dd23)

postmaster at open-mesh.org postmaster at open-mesh.org
Sun Sep 15 17:49:39 CEST 2013


Repository : ssh://git@open-mesh.org/batmand

On branch  : master

>---------------------------------------------------------------

commit e22dd235a9fcf002bc504c812e94a89586f7a486
Author: Sven Eckelmann <sven at narfation.org>
Date:   Sun Sep 15 17:44:36 2013 +0200

    Use POSIX daemon function instead of self-written one
    
    Signed-off-by: Sven Eckelmann <sven at narfation.org>


>---------------------------------------------------------------

e22dd235a9fcf002bc504c812e94a89586f7a486
 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();



More information about the commits mailing list