summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Leblond <eric@regit.org>2013-07-20 12:08:33 +0200
committerEric Leblond <eric@regit.org>2013-10-10 02:31:42 +0200
commit471a5502bf16dab3a13c8c14469582897f43ee7e (patch)
treee10cf266f276da13328b9b613d58de883074f5e1
parentd5b1116cf5ad90186fbe5a74ec58c4201395f619 (diff)
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 <eric@regit.org>
-rw-r--r--src/ulogd.c30
1 files changed, 13 insertions, 17 deletions
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);