From: Michael Poole Date: Sun, 11 Mar 2007 22:13:54 +0000 (-0400) Subject: Rearrange early init printouts to not try to use log_module(). X-Git-Tag: v1.4.0-rc1~56 X-Git-Url: http://git.pk910.de/?p=srvx.git;a=commitdiff_plain;h=17bd13e7864fd229f8a9b47e5216f9e83976d6c1 Rearrange early init printouts to not try to use log_module(). src/main.c (main): Before log_init() is called and we register MAIN_LOG, we cannot log using it -- so do not try to. --- diff --git a/src/main.c b/src/main.c index bffe2be..e5556a8 100644 --- a/src/main.c +++ b/src/main.c @@ -235,10 +235,10 @@ int main(int argc, char *argv[]) boot_time = time(&now); } - log_module(MAIN_LOG, LOG_INFO, "Initializing daemon..."); + fprintf(stdout, "Initializing daemon...\n"); if (!conf_read(services_config)) { - log_module(MAIN_LOG, LOG_FATAL, "Unable to read %s.", services_config); - exit(0); + fprintf(stderr, "Unable to read %s.\n", services_config); + exit(1); } conf_register_reload(uplink_compile); @@ -247,26 +247,30 @@ int main(int argc, char *argv[]) /* Attempt to fork into the background if daemon mode is on. */ pid = fork(); if (pid < 0) { - log_module(MAIN_LOG, LOG_FATAL, "Unable to fork: %s", strerror(errno)); + fprintf(stderr, "Unable to fork: %s\n", strerror(errno)); } else if (pid > 0) { - log_module(MAIN_LOG, LOG_INFO, "Forking into the background (pid: %i)...", pid); + fprintf(stdout, "Forking into the background (pid: %d)...", pid); exit(0); } setsid(); - /* Close these since we should not use them from now on. */ - fclose(stdin); - fclose(stdout); - fclose(stderr); } - if ((file_out = fopen(PID_FILE, "w")) == NULL) { + file_out = fopen(PID_FILE, "w"); + if (file_out == NULL) { /* Create the main process' pid file */ - log_module(MAIN_LOG, LOG_ERROR, "Unable to create PID file: %s", strerror(errno)); + fprintf(stderr, "Unable to create PID file: %s", strerror(errno)); } else { fprintf(file_out, "%i\n", (int)getpid()); fclose(file_out); } + if (daemon) { + /* Close these since we should not use them from now on. */ + fclose(stdin); + fclose(stdout); + fclose(stderr); + } + services_argc = argc; services_argv = argv;