From bd57d1b788a3aad681f87e67c5985b1d16b2ccb4 Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Fri, 3 Jul 2009 02:45:24 -0300 Subject: [PATCH] Only start logging after successfully starting server. User GLib log messages instead of printing to stderr, but only set log handler to syslog after successfully start waiting for connections. Then, the user will get proper error messages at the console if proxy cannot be started. --- popproxy.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/popproxy.c b/popproxy.c index 0f01f35..99a2352 100644 --- a/popproxy.c +++ b/popproxy.c @@ -86,15 +86,18 @@ int main (int argc, char **argv) struct pop_address pop_address; gnutls_global_init (); - pop_log_init (); configfile = CONFFILE; opt_ctx = g_option_context_new (""); g_option_context_add_main_entries (opt_ctx, opt_entries, NULL); - if (!g_option_context_parse (opt_ctx, &argc, &argv, NULL)) + + error = NULL; + if (!g_option_context_parse (opt_ctx, &argc, &argv, &error)) { - g_log (NULL, G_LOG_LEVEL_WARNING | G_LOG_FLAG_FATAL, - "Could not parse command line options."); + g_critical ("Could not parse command line options: %s.", + error->message); + g_error_free (error); + exit (1); } g_option_context_free (opt_ctx); @@ -104,8 +107,8 @@ int main (int argc, char **argv) if (g_key_file_load_from_file (keyfile, configfile, G_KEY_FILE_NONE, &error) == FALSE) { - fprintf (stderr, "Could not load configuration file %s: %s.\n", - configfile, error->message); + g_critical ("Could not load configuration file %s: %s.", + configfile, error->message); g_error_free (error); exit (1); } @@ -133,7 +136,7 @@ int main (int argc, char **argv) server_address = g_strdup ("127.0.0.1"); g_error_free (error); } - + error = NULL; server_port = g_key_file_get_string (keyfile, "global", "server_port", &error); if (server_port == NULL && error != NULL) @@ -148,11 +151,13 @@ int main (int argc, char **argv) server_fd = hc_tcp_server (port); if (server_fd < 0) { - fprintf (stderr, "Could not create server.\n"); + g_critical ("Could not create server."); exit (1); } hc_server_add_watch (server_fd, new_client, &pop_address); + pop_log_init (); + g_message ("Listening at %s:%s.", conf_address, port); if (!foreground) -- 2.20.1