Ben Lentz wrote: > Hmmm... file descriptors for STDIN, STDOUT, and STDERR should be closed, > too... the setsid() detaches the controlling terminal but a terminal > still hangs at logout after starting the daemon. A quick-and-dirty patch > is attached, but there's probably a "better" way to do this. I have applied a similar patch. I have also moved the initialization before the daemonization so that the error messages that may occur are still printed ;) -- "Los honestos son inadaptados sociales" -- Les Luthiers
Index: src/main.c =================================================================== --- src/main.c (revisión: 7171) +++ src/main.c (copia de trabajo) @@ -270,6 +270,18 @@ } close(ret); + /* + * initialization process + */ + + if (init() == -1) { + close_log(); + fprintf(stderr, "ERROR: conntrackd cannot start, please " + "check the logfile for more info\n"); + unlink(CONFIG(lockfile)); + exit(EXIT_FAILURE); + } + /* Daemonize conntrackd */ if (type == DAEMON) { pid_t pid, sid; @@ -287,23 +299,15 @@ exit(EXIT_FAILURE); } + close(STDIN_FILENO); + close(STDOUT_FILENO); + close(STDERR_FILENO); + dlog(STATE(log), LOG_NOTICE, "-- starting in daemon mode --"); } else dlog(STATE(log), LOG_NOTICE, "-- starting in console mode --"); /* - * initialization process - */ - - if (init() == -1) { - close_log(); - fprintf(stderr, "ERROR: conntrackd cannot start, please " - "check the logfile for more info\n"); - unlink(CONFIG(lockfile)); - exit(EXIT_FAILURE); - } - - /* * run main process */ run(); Index: ChangeLog =================================================================== --- ChangeLog (revisión: 7171) +++ ChangeLog (copia de trabajo) @@ -29,6 +29,7 @@ o minor irrelevant fixes for uncommon error paths and fix several typos o detach daemon from its terminal (Ben Lenitz <BLentz@xxxxxxxxxxxxxxxxx>) o obsolete `-S' option: Use information provided by the config file +o daemonize conntrackd after initialization version 0.9.5 (2007/07/29) ------------------------------