From 9ce31ec4d8ef8bdf35dff65463744a4da648228d Mon Sep 17 00:00:00 2001 From: "Nicholas J. Kain" Date: Fri, 12 Nov 2010 19:50:04 -0500 Subject: [PATCH] Make background() idempotent in a cleaner way. --- ndhc/ndhc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ndhc/ndhc.c b/ndhc/ndhc.c index c40b7e4..075dc0b 100644 --- a/ndhc/ndhc.c +++ b/ndhc/ndhc.c @@ -188,11 +188,12 @@ static void signal_handler(int sig) static void background(void) { - if (daemon(0, 0) == -1) { + static char called; + if (!called && daemon(0, 0) == -1) { perror("fork"); exit(EXIT_SUCCESS); } - client_config.foreground = 1; /* Do not fork again. */ + called = 1; /* Do not fork again. */ } static void handle_timeout(void)