Make background() idempotent in a cleaner way.

This commit is contained in:
Nicholas J. Kain 2010-11-12 19:50:04 -05:00
parent 5f55dbc3ff
commit 9ce31ec4d8

View File

@ -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)