From 17bd13e7864fd229f8a9b47e5216f9e83976d6c1 Mon Sep 17 00:00:00 2001 From: Michael Poole Date: Sun, 11 Mar 2007 18:13:54 -0400 Subject: [PATCH] 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. --- src/main.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) 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; -- 2.20.1