From: Eric Leblond Date: Sat, 20 Jul 2013 10:08:33 +0000 (+0200) Subject: ulogd: use daemon() function X-Git-Tag: ulogd-2.0.3~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=471a5502bf16dab3a13c8c14469582897f43ee7e;p=thirdparty%2Fulogd2.git ulogd: use daemon() function This patches update the daemonization code. It is done earlier and it uses the daemon(à function which is used for daemonization by most projects. Signed-off-by: Eric Leblond --- diff --git a/src/ulogd.c b/src/ulogd.c index c1aba77..2c0fbd1 100644 --- a/src/ulogd.c +++ b/src/ulogd.c @@ -1399,6 +1399,19 @@ int main(int argc, char* argv[]) " with daemon mode).\n"); } + if (daemonize){ + if (daemon(0, 0) < 0) { + ulogd_log(ULOGD_FATAL, "can't daemonize: %s (%d)", + errno, strerror(errno)); + warn_and_exit(daemonize); + } + } + + if (ulogd_pidfile) { + if (write_pidfile(daemonize) < 0) + warn_and_exit(0); + } + if (config_register_file(ulogd_configfile)) { ulogd_log(ULOGD_FATAL, "error registering configfile \"%s\"\n", ulogd_configfile); @@ -1450,23 +1463,6 @@ int main(int argc, char* argv[]) } } - - if (daemonize){ - if (fork()) { - exit(0); - } - if (logfile != stdout) - fclose(stdout); - fclose(stderr); - fclose(stdin); - setsid(); - } - - if (ulogd_pidfile) { - if (write_pidfile(daemonize) < 0) - warn_and_exit(0); - } - signal(SIGTERM, &sigterm_handler); signal(SIGINT, &sigterm_handler); signal(SIGHUP, &signal_handler);