summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorGuillem Jover <guillem@hadrons.org>2013-03-25 12:44:07 +0100
committerSamuel Ortiz <sameo@linux.intel.com>2013-03-25 13:47:20 +0100
commitc0a69ef21a0d866ce9934579579b4e7f4b73b14b (patch)
treedf3209ed1c8516dc10cba8c796e9ed278bae087f /src/main.c
parentc4f3e41d69e019e0474692f3157c0a0135fcc08c (diff)
downloadneard-c0a69ef21a0d866ce9934579579b4e7f4b73b14b.tar.gz
neard-c0a69ef21a0d866ce9934579579b4e7f4b73b14b.tar.bz2
neard-c0a69ef21a0d866ce9934579579b4e7f4b73b14b.zip
main: Wait to daemonize to just before entering the main loop
To be able to get correct exit codes in case of error, we have to delay the daemonization to just before entering the main loop. Otherwise the init scripts might assume everything started fine and go ahead when that was not the case. The initialization error messages are printed to syslog instead of stderr, which would need a rework in the future of either the logging functions, or the call sites to distinguish what belongs where. But at least for now we get correct exit values.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/main.c b/src/main.c
index a121f63..b9f94c5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -172,13 +172,6 @@ int main(int argc, char *argv[])
exit(0);
}
- if (option_detach == TRUE) {
- if (daemon(0, 0)) {
- perror("Can't start daemon");
- exit(1);
- }
- }
-
main_loop = g_main_loop_new(NULL, FALSE);
dbus_error_init(&err);
@@ -218,6 +211,13 @@ int main(int argc, char *argv[])
__near_plugin_init(option_plugin, option_noplugin);
+ if (option_detach == TRUE) {
+ if (daemon(0, 0)) {
+ perror("Can't start daemon");
+ exit(1);
+ }
+ }
+
memset(&sa, 0, sizeof(sa));
sa.sa_handler = sig_term;
sigaction(SIGINT, &sa, NULL);