From 28bcb8bdf568875eeea1349e39b7958d77c8fcc1 Mon Sep 17 00:00:00 2001 From: Thomas Jansen Date: Sat, 25 Sep 2010 15:00:43 +0200 Subject: eliminate g_error() usage Replaced all occurrences of g_error() with MPD_ERROR() located in a new header file 'mpd_error.h'. This macro uses g_critical() to print the error message and then exits gracefully in contrast to g_error() which would internally call abort() to produce a core dump. The macro name is distinctive and allows to find all places with dubious error handling. The long-term goal is to get rid of MPD_ERROR() altogether. To facilitate the eventual removal of this macro it was added in a new header file rather than to an existing header file. This fixes #2995 and #3007. --- src/log.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/log.c') diff --git a/src/log.c b/src/log.c index dc7628871..556c8b04f 100644 --- a/src/log.c +++ b/src/log.c @@ -22,6 +22,7 @@ #include "conf.h" #include "utils.h" #include "fd_util.h" +#include "mpd_error.h" #include #include @@ -60,9 +61,9 @@ static void redirect_logs(int fd) { assert(fd >= 0); if (dup2(fd, STDOUT_FILENO) < 0) - g_error("problems dup2 stdout : %s\n", strerror(errno)); + MPD_ERROR("problems dup2 stdout : %s\n", strerror(errno)); if (dup2(fd, STDERR_FILENO) < 0) - g_error("problems dup2 stderr : %s\n", strerror(errno)); + MPD_ERROR("problems dup2 stderr : %s\n", strerror(errno)); } static const char *log_date(void) @@ -138,8 +139,8 @@ log_init_file(const char *path, unsigned line) out_filename = path; out_fd = open_log_file(); if (out_fd < 0) - g_error("problem opening log file \"%s\" (config line %u) for " - "writing\n", path, line); + MPD_ERROR("problem opening log file \"%s\" (config line %u) " + "for writing\n", path, line); g_log_set_default_handler(file_log_func, NULL); } @@ -216,8 +217,8 @@ parse_log_level(const char *value, unsigned line) else if (0 == strcmp(value, "verbose")) return G_LOG_LEVEL_DEBUG; else { - g_error("unknown log level \"%s\" at line %u\n", - value, line); + MPD_ERROR("unknown log level \"%s\" at line %u\n", + value, line); return G_LOG_LEVEL_MESSAGE; } } @@ -252,8 +253,8 @@ void log_init(bool verbose, bool use_stdout) available) */ log_init_syslog(); #else - g_error("config parameter \"%s\" not found\n", - CONF_LOG_FILE); + MPD_ERROR("config parameter \"%s\" not found\n", + CONF_LOG_FILE); #endif #ifdef HAVE_SYSLOG } else if (strcmp(param->value, "syslog") == 0) { -- cgit v1.2.3