Commit 28bcb8bd authored by Thomas Jansen's avatar Thomas Jansen

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.
parent 9af9fd14
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "output_plugin.h" #include "output_plugin.h"
#include "output_all.h" #include "output_all.h"
#include "conf.h" #include "conf.h"
#include "mpd_error.h"
#include <glib.h> #include <glib.h>
...@@ -52,6 +53,7 @@ void initAudioConfig(void) ...@@ -52,6 +53,7 @@ void initAudioConfig(void)
ret = audio_format_parse(&configured_audio_format, param->value, ret = audio_format_parse(&configured_audio_format, param->value,
true, &error); true, &error);
if (!ret) if (!ret)
g_error("error parsing \"%s\" at line %i: %s", MPD_ERROR("error parsing \"%s\" at line %i: %s",
CONF_AUDIO_OUTPUT_FORMAT, param->line, error->message); CONF_AUDIO_OUTPUT_FORMAT, param->line,
error->message);
} }
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "decoder_plugin.h" #include "decoder_plugin.h"
#include "output_list.h" #include "output_list.h"
#include "ls.h" #include "ls.h"
#include "mpd_error.h"
#ifdef ENABLE_ENCODER #ifdef ENABLE_ENCODER
#include "encoder_list.h" #include "encoder_list.h"
...@@ -155,10 +156,8 @@ parse_cmdline(int argc, char **argv, struct options *options, ...@@ -155,10 +156,8 @@ parse_cmdline(int argc, char **argv, struct options *options,
ret = g_option_context_parse(context, &argc, &argv, &error); ret = g_option_context_parse(context, &argc, &argv, &error);
g_option_context_free(context); g_option_context_free(context);
if (!ret) { if (!ret)
g_error("option parsing failed: %s\n", error->message); MPD_ERROR("option parsing failed: %s\n", error->message);
exit(1);
}
if (option_version) if (option_version)
version(); version();
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "tokenizer.h" #include "tokenizer.h"
#include "path.h" #include "path.h"
#include "glib_compat.h" #include "glib_compat.h"
#include "mpd_error.h"
#include <glib.h> #include <glib.h>
...@@ -498,8 +499,8 @@ config_get_path(const char *name) ...@@ -498,8 +499,8 @@ config_get_path(const char *name)
path = parsePath(param->value); path = parsePath(param->value);
if (path == NULL) if (path == NULL)
g_error("error parsing \"%s\" at line %i\n", MPD_ERROR("error parsing \"%s\" at line %i\n",
name, param->line); name, param->line);
g_free(param->value); g_free(param->value);
return param->value = path; return param->value = path;
...@@ -517,7 +518,8 @@ config_get_unsigned(const char *name, unsigned default_value) ...@@ -517,7 +518,8 @@ config_get_unsigned(const char *name, unsigned default_value)
value = strtol(param->value, &endptr, 0); value = strtol(param->value, &endptr, 0);
if (*endptr != 0 || value < 0) if (*endptr != 0 || value < 0)
g_error("Not a valid non-negative number in line %i", param->line); MPD_ERROR("Not a valid non-negative number in line %i",
param->line);
return (unsigned)value; return (unsigned)value;
} }
...@@ -534,10 +536,10 @@ config_get_positive(const char *name, unsigned default_value) ...@@ -534,10 +536,10 @@ config_get_positive(const char *name, unsigned default_value)
value = strtol(param->value, &endptr, 0); value = strtol(param->value, &endptr, 0);
if (*endptr != 0) if (*endptr != 0)
g_error("Not a valid number in line %i", param->line); MPD_ERROR("Not a valid number in line %i", param->line);
if (value <= 0) if (value <= 0)
g_error("Not a positive number in line %i", param->line); MPD_ERROR("Not a positive number in line %i", param->line);
return (unsigned)value; return (unsigned)value;
} }
...@@ -569,9 +571,9 @@ bool config_get_bool(const char *name, bool default_value) ...@@ -569,9 +571,9 @@ bool config_get_bool(const char *name, bool default_value)
success = get_bool(param->value, &value); success = get_bool(param->value, &value);
if (!success) if (!success)
g_error("%s is not a boolean value (yes, true, 1) or " MPD_ERROR("%s is not a boolean value (yes, true, 1) or "
"(no, false, 0) on line %i\n", "(no, false, 0) on line %i\n",
name, param->line); name, param->line);
return value; return value;
} }
...@@ -601,10 +603,10 @@ config_get_block_unsigned(const struct config_param *param, const char *name, ...@@ -601,10 +603,10 @@ config_get_block_unsigned(const struct config_param *param, const char *name,
value = strtol(bp->value, &endptr, 0); value = strtol(bp->value, &endptr, 0);
if (*endptr != 0) if (*endptr != 0)
g_error("Not a valid number in line %i", bp->line); MPD_ERROR("Not a valid number in line %i", bp->line);
if (value < 0) if (value < 0)
g_error("Not a positive number in line %i", bp->line); MPD_ERROR("Not a positive number in line %i", bp->line);
return (unsigned)value; return (unsigned)value;
} }
...@@ -621,9 +623,9 @@ config_get_block_bool(const struct config_param *param, const char *name, ...@@ -621,9 +623,9 @@ config_get_block_bool(const struct config_param *param, const char *name,
success = get_bool(bp->value, &value); success = get_bool(bp->value, &value);
if (!success) if (!success)
g_error("%s is not a boolean value (yes, true, 1) or " MPD_ERROR("%s is not a boolean value (yes, true, 1) or "
"(no, false, 0) on line %i\n", "(no, false, 0) on line %i\n",
name, bp->line); name, bp->line);
return value; return value;
} }
...@@ -65,23 +65,23 @@ daemonize_kill(void) ...@@ -65,23 +65,23 @@ daemonize_kill(void)
int pid, ret; int pid, ret;
if (pidfile == NULL) if (pidfile == NULL)
g_error("no pid_file specified in the config file"); MPD_ERROR("no pid_file specified in the config file");
fp = fopen(pidfile, "r"); fp = fopen(pidfile, "r");
if (fp == NULL) if (fp == NULL)
g_error("unable to open pid file \"%s\": %s", MPD_ERROR("unable to open pid file \"%s\": %s",
pidfile, g_strerror(errno)); pidfile, g_strerror(errno));
if (fscanf(fp, "%i", &pid) != 1) { if (fscanf(fp, "%i", &pid) != 1) {
g_error("unable to read the pid from file \"%s\"", MPD_ERROR("unable to read the pid from file \"%s\"",
pidfile); pidfile);
} }
fclose(fp); fclose(fp);
ret = kill(pid, SIGTERM); ret = kill(pid, SIGTERM);
if (ret < 0) if (ret < 0)
g_error("unable to kill proccess %i: %s", MPD_ERROR("unable to kill proccess %i: %s",
pid, g_strerror(errno)); pid, g_strerror(errno));
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
...@@ -102,8 +102,8 @@ daemonize_set_user(void) ...@@ -102,8 +102,8 @@ daemonize_set_user(void)
/* set gid */ /* set gid */
if (user_gid != (gid_t)-1 && user_gid != getgid()) { if (user_gid != (gid_t)-1 && user_gid != getgid()) {
if (setgid(user_gid) == -1) { if (setgid(user_gid) == -1) {
g_error("cannot setgid to %d: %s", MPD_ERROR("cannot setgid to %d: %s",
(int)user_gid, g_strerror(errno)); (int)user_gid, g_strerror(errno));
} }
} }
...@@ -121,8 +121,8 @@ daemonize_set_user(void) ...@@ -121,8 +121,8 @@ daemonize_set_user(void)
/* set uid */ /* set uid */
if (user_uid != (uid_t)-1 && user_uid != getuid() && if (user_uid != (uid_t)-1 && user_uid != getuid() &&
setuid(user_uid) == -1) { setuid(user_uid) == -1) {
g_error("cannot change to uid of user \"%s\": %s", MPD_ERROR("cannot change to uid of user \"%s\": %s",
user_name, g_strerror(errno)); user_name, g_strerror(errno));
} }
} }
...@@ -136,7 +136,7 @@ daemonize_detach(void) ...@@ -136,7 +136,7 @@ daemonize_detach(void)
#ifdef HAVE_DAEMON #ifdef HAVE_DAEMON
if (daemon(0, 1)) if (daemon(0, 1))
g_error("daemon() failed: %s", g_strerror(errno)); MPD_ERROR("daemon() failed: %s", g_strerror(errno));
#elif defined(HAVE_FORK) #elif defined(HAVE_FORK)
...@@ -144,7 +144,7 @@ daemonize_detach(void) ...@@ -144,7 +144,7 @@ daemonize_detach(void)
switch (fork()) { switch (fork()) {
case -1: case -1:
g_error("fork() failed: %s", g_strerror(errno)); MPD_ERROR("fork() failed: %s", g_strerror(errno));
case 0: case 0:
break; break;
default: default:
...@@ -155,14 +155,14 @@ daemonize_detach(void) ...@@ -155,14 +155,14 @@ daemonize_detach(void)
/* release the current working directory */ /* release the current working directory */
if (chdir("/") < 0) if (chdir("/") < 0)
g_error("problems changing to root directory"); MPD_ERROR("problems changing to root directory");
/* detach from the current session */ /* detach from the current session */
setsid(); setsid();
#else #else
g_error("no support for daemonizing"); MPD_ERROR("no support for daemonizing");
#endif #endif
g_debug("daemonized!"); g_debug("daemonized!");
...@@ -179,8 +179,8 @@ daemonize(bool detach) ...@@ -179,8 +179,8 @@ daemonize(bool detach)
g_debug("opening pid file"); g_debug("opening pid file");
fp = fopen(pidfile, "w+"); fp = fopen(pidfile, "w+");
if (!fp) { if (!fp) {
g_error("could not create pid file \"%s\": %s", MPD_ERROR("could not create pid file \"%s\": %s",
pidfile, g_strerror(errno)); pidfile, g_strerror(errno));
} }
} }
...@@ -200,7 +200,7 @@ daemonize_init(const char *user, const char *group, const char *_pidfile) ...@@ -200,7 +200,7 @@ daemonize_init(const char *user, const char *group, const char *_pidfile)
if (user) { if (user) {
struct passwd *pwd = getpwnam(user); struct passwd *pwd = getpwnam(user);
if (!pwd) if (!pwd)
g_error("no such user \"%s\"", user); MPD_ERROR("no such user \"%s\"", user);
user_uid = pwd->pw_uid; user_uid = pwd->pw_uid;
user_gid = pwd->pw_gid; user_gid = pwd->pw_gid;
...@@ -214,7 +214,7 @@ daemonize_init(const char *user, const char *group, const char *_pidfile) ...@@ -214,7 +214,7 @@ daemonize_init(const char *user, const char *group, const char *_pidfile)
if (group) { if (group) {
struct group *grp = grp = getgrnam(group); struct group *grp = grp = getgrnam(group);
if (!grp) if (!grp)
g_error("no such group \"%s\"", group); MPD_ERROR("no such group \"%s\"", group);
user_gid = grp->gr_gid; user_gid = grp->gr_gid;
had_group = true; had_group = true;
} }
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#ifndef DAEMON_H #ifndef DAEMON_H
#define DAEMON_H #define DAEMON_H
#include "mpd_error.h"
#include <stdbool.h> #include <stdbool.h>
#ifndef WIN32 #ifndef WIN32
...@@ -51,7 +53,7 @@ daemonize_kill(void); ...@@ -51,7 +53,7 @@ daemonize_kill(void);
#include <glib.h> #include <glib.h>
static inline void static inline void
daemonize_kill(void) daemonize_kill(void)
{ g_error("--kill is not available on WIN32"); } { MPD_ERROR("--kill is not available on WIN32"); }
#endif #endif
/** /**
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "config.h" #include "config.h"
#include "decoder_api.h" #include "decoder_api.h"
#include "mpd_error.h"
#include <glib.h> #include <glib.h>
#include <mikmod.h> #include <mikmod.h>
...@@ -110,8 +111,8 @@ mikmod_decoder_init(const struct config_param *param) ...@@ -110,8 +111,8 @@ mikmod_decoder_init(const struct config_param *param)
mikmod_sample_rate = config_get_block_unsigned(param, "sample_rate", mikmod_sample_rate = config_get_block_unsigned(param, "sample_rate",
44100); 44100);
if (!audio_valid_sample_rate(mikmod_sample_rate)) if (!audio_valid_sample_rate(mikmod_sample_rate))
g_error("Invalid sample rate in line %d: %u", MPD_ERROR("Invalid sample rate in line %d: %u",
param->line, mikmod_sample_rate); param->line, mikmod_sample_rate);
md_device = 0; md_device = 0;
md_reverb = 0; md_reverb = 0;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "decoder_plugin.h" #include "decoder_plugin.h"
#include "utils.h" #include "utils.h"
#include "conf.h" #include "conf.h"
#include "mpd_error.h"
#include <glib.h> #include <glib.h>
...@@ -198,8 +199,8 @@ decoder_plugin_config(const char *plugin_name) ...@@ -198,8 +199,8 @@ decoder_plugin_config(const char *plugin_name)
const char *name = const char *name =
config_get_block_string(param, "plugin", NULL); config_get_block_string(param, "plugin", NULL);
if (name == NULL) if (name == NULL)
g_error("decoder configuration without 'plugin' name in line %d", MPD_ERROR("decoder configuration without 'plugin' name in line %d",
param->line); param->line);
if (strcmp(name, plugin_name) == 0) if (strcmp(name, plugin_name) == 0)
return param; return param;
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "mapper.h" #include "mapper.h"
#include "path.h" #include "path.h"
#include "uri.h" #include "uri.h"
#include "mpd_error.h"
#include <glib.h> #include <glib.h>
...@@ -479,5 +480,5 @@ decoder_thread_start(struct decoder_control *dc) ...@@ -479,5 +480,5 @@ decoder_thread_start(struct decoder_control *dc)
dc->thread = g_thread_create(decoder_task, dc, true, &e); dc->thread = g_thread_create(decoder_task, dc, true, &e);
if (dc->thread == NULL) if (dc->thread == NULL)
g_error("Failed to spawn decoder task: %s", e->message); MPD_ERROR("Failed to spawn decoder task: %s", e->message);
} }
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "encoder_plugin.h" #include "encoder_plugin.h"
#include "tag.h" #include "tag.h"
#include "audio_format.h" #include "audio_format.h"
#include "mpd_error.h"
#include <vorbis/vorbisenc.h> #include <vorbis/vorbisenc.h>
...@@ -374,7 +375,7 @@ vorbis_encoder_read(struct encoder *_encoder, void *_dest, size_t length) ...@@ -374,7 +375,7 @@ vorbis_encoder_read(struct encoder *_encoder, void *_dest, size_t length)
if (nbytes > length) if (nbytes > length)
/* XXX better error handling */ /* XXX better error handling */
g_error("buffer too small"); MPD_ERROR("buffer too small");
memcpy(dest, page.header, page.header_len); memcpy(dest, page.header, page.header_len);
memcpy(dest + page.header_len, page.body, page.body_len); memcpy(dest + page.header_len, page.body, page.body_len);
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "config.h" #include "config.h"
#include "event_pipe.h" #include "event_pipe.h"
#include "fd_util.h" #include "fd_util.h"
#include "mpd_error.h"
#include <stdbool.h> #include <stdbool.h>
#include <assert.h> #include <assert.h>
...@@ -68,7 +69,7 @@ main_notify_event(G_GNUC_UNUSED GIOChannel *source, ...@@ -68,7 +69,7 @@ main_notify_event(G_GNUC_UNUSED GIOChannel *source,
buffer, sizeof(buffer), buffer, sizeof(buffer),
&bytes_read, &error); &bytes_read, &error);
if (status == G_IO_STATUS_ERROR) if (status == G_IO_STATUS_ERROR)
g_error("error reading from pipe: %s", error->message); MPD_ERROR("error reading from pipe: %s", error->message);
bool events[PIPE_EVENT_MAX]; bool events[PIPE_EVENT_MAX];
g_mutex_lock(event_pipe_mutex); g_mutex_lock(event_pipe_mutex);
...@@ -91,7 +92,7 @@ void event_pipe_init(void) ...@@ -91,7 +92,7 @@ void event_pipe_init(void)
ret = pipe_cloexec_nonblock(event_pipe); ret = pipe_cloexec_nonblock(event_pipe);
if (ret < 0) if (ret < 0)
g_error("Couldn't open pipe: %s", strerror(errno)); MPD_ERROR("Couldn't open pipe: %s", strerror(errno));
#ifndef G_OS_WIN32 #ifndef G_OS_WIN32
channel = g_io_channel_unix_new(event_pipe[0]); channel = g_io_channel_unix_new(event_pipe[0]);
...@@ -150,7 +151,7 @@ void event_pipe_emit(enum pipe_event event) ...@@ -150,7 +151,7 @@ void event_pipe_emit(enum pipe_event event)
w = write(event_pipe[1], "", 1); w = write(event_pipe[1], "", 1);
if (w < 0 && errno != EAGAIN && errno != EINTR) if (w < 0 && errno != EAGAIN && errno != EINTR)
g_error("error writing to pipe: %s", strerror(errno)); MPD_ERROR("error writing to pipe: %s", strerror(errno));
} }
void event_pipe_emit_fast(enum pipe_event event) void event_pipe_emit_fast(enum pipe_event event)
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "inotify_source.h" #include "inotify_source.h"
#include "fifo_buffer.h" #include "fifo_buffer.h"
#include "fd_util.h" #include "fd_util.h"
#include "mpd_error.h"
#include <sys/inotify.h> #include <sys/inotify.h>
#include <unistd.h> #include <unistd.h>
...@@ -68,13 +69,14 @@ mpd_inotify_in_event(G_GNUC_UNUSED GIOChannel *_source, ...@@ -68,13 +69,14 @@ mpd_inotify_in_event(G_GNUC_UNUSED GIOChannel *_source,
dest = fifo_buffer_write(source->buffer, &length); dest = fifo_buffer_write(source->buffer, &length);
if (dest == NULL) if (dest == NULL)
g_error("buffer full"); MPD_ERROR("buffer full");
nbytes = read(source->fd, dest, length); nbytes = read(source->fd, dest, length);
if (nbytes < 0) if (nbytes < 0)
g_error("failed to read from inotify: %s", g_strerror(errno)); MPD_ERROR("failed to read from inotify: %s",
g_strerror(errno));
if (nbytes == 0) if (nbytes == 0)
g_error("end of file from inotify"); MPD_ERROR("end of file from inotify");
fifo_buffer_append(source->buffer, nbytes); fifo_buffer_append(source->buffer, nbytes);
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "conf.h" #include "conf.h"
#include "utils.h" #include "utils.h"
#include "fd_util.h" #include "fd_util.h"
#include "mpd_error.h"
#include <assert.h> #include <assert.h>
#include <sys/types.h> #include <sys/types.h>
...@@ -60,9 +61,9 @@ static void redirect_logs(int fd) ...@@ -60,9 +61,9 @@ static void redirect_logs(int fd)
{ {
assert(fd >= 0); assert(fd >= 0);
if (dup2(fd, STDOUT_FILENO) < 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) 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) static const char *log_date(void)
...@@ -138,8 +139,8 @@ log_init_file(const char *path, unsigned line) ...@@ -138,8 +139,8 @@ log_init_file(const char *path, unsigned line)
out_filename = path; out_filename = path;
out_fd = open_log_file(); out_fd = open_log_file();
if (out_fd < 0) if (out_fd < 0)
g_error("problem opening log file \"%s\" (config line %u) for " MPD_ERROR("problem opening log file \"%s\" (config line %u) "
"writing\n", path, line); "for writing\n", path, line);
g_log_set_default_handler(file_log_func, NULL); g_log_set_default_handler(file_log_func, NULL);
} }
...@@ -216,8 +217,8 @@ parse_log_level(const char *value, unsigned line) ...@@ -216,8 +217,8 @@ parse_log_level(const char *value, unsigned line)
else if (0 == strcmp(value, "verbose")) else if (0 == strcmp(value, "verbose"))
return G_LOG_LEVEL_DEBUG; return G_LOG_LEVEL_DEBUG;
else { else {
g_error("unknown log level \"%s\" at line %u\n", MPD_ERROR("unknown log level \"%s\" at line %u\n",
value, line); value, line);
return G_LOG_LEVEL_MESSAGE; return G_LOG_LEVEL_MESSAGE;
} }
} }
...@@ -252,8 +253,8 @@ void log_init(bool verbose, bool use_stdout) ...@@ -252,8 +253,8 @@ void log_init(bool verbose, bool use_stdout)
available) */ available) */
log_init_syslog(); log_init_syslog();
#else #else
g_error("config parameter \"%s\" not found\n", MPD_ERROR("config parameter \"%s\" not found\n",
CONF_LOG_FILE); CONF_LOG_FILE);
#endif #endif
#ifdef HAVE_SYSLOG #ifdef HAVE_SYSLOG
} else if (strcmp(param->value, "syslog") == 0) { } else if (strcmp(param->value, "syslog") == 0) {
......
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
#include "dirvec.h" #include "dirvec.h"
#include "songvec.h" #include "songvec.h"
#include "tag_pool.h" #include "tag_pool.h"
#include "mpd_error.h"
#ifdef ENABLE_INOTIFY #ifdef ENABLE_INOTIFY
#include "inotify_update.h" #include "inotify_update.h"
...@@ -141,7 +142,7 @@ glue_db_init_and_load(void) ...@@ -141,7 +142,7 @@ glue_db_init_and_load(void)
} }
if (path == NULL) if (path == NULL)
g_error(CONF_DB_FILE " setting missing"); MPD_ERROR(CONF_DB_FILE " setting missing");
db_init(path); db_init(path);
...@@ -175,7 +176,7 @@ glue_sticker_init(void) ...@@ -175,7 +176,7 @@ glue_sticker_init(void)
success = sticker_global_init(config_get_path(CONF_STICKER_FILE), success = sticker_global_init(config_get_path(CONF_STICKER_FILE),
&error); &error);
if (!success) if (!success)
g_error("%s", error->message); MPD_ERROR("%s", error->message);
#endif #endif
} }
...@@ -197,14 +198,14 @@ static void winsock_init(void) ...@@ -197,14 +198,14 @@ static void winsock_init(void)
retval = WSAStartup(MAKEWORD(2, 2), &sockinfo); retval = WSAStartup(MAKEWORD(2, 2), &sockinfo);
if(retval != 0) if(retval != 0)
{ {
g_error("Attempt to open Winsock2 failed; error code %d\n", MPD_ERROR("Attempt to open Winsock2 failed; error code %d\n",
retval); retval);
} }
if (LOBYTE(sockinfo.wVersion) != 2) if (LOBYTE(sockinfo.wVersion) != 2)
{ {
g_error("We use Winsock2 but your version is either too new or " MPD_ERROR("We use Winsock2 but your version is either too new "
"old; please install Winsock 2.x\n"); "or old; please install Winsock 2.x\n");
} }
#endif #endif
} }
...@@ -226,8 +227,8 @@ initialize_decoder_and_player(void) ...@@ -226,8 +227,8 @@ initialize_decoder_and_player(void)
if (param != NULL) { if (param != NULL) {
buffer_size = strtol(param->value, &test, 10); buffer_size = strtol(param->value, &test, 10);
if (*test != '\0' || buffer_size <= 0) if (*test != '\0' || buffer_size <= 0)
g_error("buffer size \"%s\" is not a positive integer, " MPD_ERROR("buffer size \"%s\" is not a positive integer, "
"line %i\n", param->value, param->line); "line %i\n", param->value, param->line);
} else } else
buffer_size = DEFAULT_BUFFER_SIZE; buffer_size = DEFAULT_BUFFER_SIZE;
...@@ -236,15 +237,15 @@ initialize_decoder_and_player(void) ...@@ -236,15 +237,15 @@ initialize_decoder_and_player(void)
buffered_chunks = buffer_size / CHUNK_SIZE; buffered_chunks = buffer_size / CHUNK_SIZE;
if (buffered_chunks >= 1 << 15) if (buffered_chunks >= 1 << 15)
g_error("buffer size \"%li\" is too big\n", (long)buffer_size); MPD_ERROR("buffer size \"%li\" is too big\n", (long)buffer_size);
param = config_get_param(CONF_BUFFER_BEFORE_PLAY); param = config_get_param(CONF_BUFFER_BEFORE_PLAY);
if (param != NULL) { if (param != NULL) {
perc = strtod(param->value, &test); perc = strtod(param->value, &test);
if (*test != '%' || perc < 0 || perc > 100) { if (*test != '%' || perc < 0 || perc > 100) {
g_error("buffered before play \"%s\" is not a positive " MPD_ERROR("buffered before play \"%s\" is not a positive "
"percentage and less than 100 percent, line %i", "percentage and less than 100 percent, line %i",
param->value, param->line); param->value, param->line);
} }
} else } else
perc = DEFAULT_BUFFER_BEFORE_PLAY; perc = DEFAULT_BUFFER_BEFORE_PLAY;
...@@ -390,7 +391,7 @@ int mpd_main(int argc, char *argv[]) ...@@ -390,7 +391,7 @@ int mpd_main(int argc, char *argv[])
database */ database */
unsigned job = update_enqueue(NULL, true); unsigned job = update_enqueue(NULL, true);
if (job == 0) if (job == 0)
g_error("directory update failed"); MPD_ERROR("directory update failed");
} }
glue_state_file_init(); glue_state_file_init();
......
/*
* Copyright (C) 2003-2010 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_ERROR_H
#define MPD_ERROR_H
#include <stdlib.h>
/* This macro is used as an intermediate step to a proper error handling
* using GError in mpd. It is used for unrecoverable error conditions
* and exits immediately. The long-term goal is to replace this macro by
* proper error handling. */
#define MPD_ERROR(...) \
{ \
g_critical(__VA_ARGS__); \
exit(EXIT_FAILURE); \
}
#endif
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "output_api.h" #include "output_api.h"
#include "encoder_plugin.h" #include "encoder_plugin.h"
#include "encoder_list.h" #include "encoder_list.h"
#include "mpd_error.h"
#include <shout/shout.h> #include <shout/shout.h>
#include <glib.h> #include <glib.h>
...@@ -101,8 +102,8 @@ static void free_shout_data(struct shout_data *sd) ...@@ -101,8 +102,8 @@ static void free_shout_data(struct shout_data *sd)
#define check_block_param(name) { \ #define check_block_param(name) { \
block_param = config_get_block_param(param, name); \ block_param = config_get_block_param(param, name); \
if (!block_param) { \ if (!block_param) { \
g_error("no \"%s\" defined for shout device defined at line " \ MPD_ERROR("no \"%s\" defined for shout device defined at line " \
"%i\n", name, param->line); \ "%i\n", name, param->line); \
} \ } \
} }
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "pipe.h" #include "pipe.h"
#include "buffer.h" #include "buffer.h"
#include "player_control.h" #include "player_control.h"
#include "mpd_error.h"
#ifndef NDEBUG #ifndef NDEBUG
#include "chunk.h" #include "chunk.h"
...@@ -122,17 +123,17 @@ audio_output_all_init(void) ...@@ -122,17 +123,17 @@ audio_output_all_init(void)
if (!audio_output_init(output, param, &error)) { if (!audio_output_init(output, param, &error)) {
if (param != NULL) if (param != NULL)
g_error("line %i: %s", MPD_ERROR("line %i: %s",
param->line, error->message); param->line, error->message)
else else
g_error("%s", error->message); MPD_ERROR("%s", error->message);
} }
/* require output names to be unique: */ /* require output names to be unique: */
for (j = 0; j < i; j++) { for (j = 0; j < i; j++) {
if (!strcmp(output->name, audio_outputs[j].name)) { if (!strcmp(output->name, audio_outputs[j].name)) {
g_error("output devices with identical " MPD_ERROR("output devices with identical "
"names: %s\n", output->name); "names: %s\n", output->name);
} }
} }
} }
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "filter_plugin.h" #include "filter_plugin.h"
#include "filter/convert_filter_plugin.h" #include "filter/convert_filter_plugin.h"
#include "filter/replay_gain_filter_plugin.h" #include "filter/replay_gain_filter_plugin.h"
#include "mpd_error.h"
#include <glib.h> #include <glib.h>
...@@ -629,5 +630,5 @@ void audio_output_thread_start(struct audio_output *ao) ...@@ -629,5 +630,5 @@ void audio_output_thread_start(struct audio_output *ao)
assert(ao->command == AO_COMMAND_NONE); assert(ao->command == AO_COMMAND_NONE);
if (!(ao->thread = g_thread_create(audio_output_task, ao, true, &e))) if (!(ao->thread = g_thread_create(audio_output_task, ao, true, &e)))
g_error("Failed to spawn output task: %s\n", e->message); MPD_ERROR("Failed to spawn output task: %s\n", e->message);
} }
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "config.h" #include "config.h"
#include "path.h" #include "path.h"
#include "conf.h" #include "conf.h"
#include "mpd_error.h"
#include <glib.h> #include <glib.h>
...@@ -64,7 +65,7 @@ path_set_fs_charset(const char *charset) ...@@ -64,7 +65,7 @@ path_set_fs_charset(const char *charset)
/* convert a space to ensure that the charset is valid */ /* convert a space to ensure that the charset is valid */
test = g_convert(" ", 1, charset, "UTF-8", NULL, NULL, NULL); test = g_convert(" ", 1, charset, "UTF-8", NULL, NULL, NULL);
if (test == NULL) if (test == NULL)
g_error("invalid filesystem charset: %s", charset); MPD_ERROR("invalid filesystem charset: %s", charset);
g_free(test); g_free(test);
g_free(fs_charset); g_free(fs_charset);
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "pcm_volume.h" #include "pcm_volume.h"
#include "pcm_utils.h" #include "pcm_utils.h"
#include "audio_format.h" #include "audio_format.h"
#include "mpd_error.h"
#include <glib.h> #include <glib.h>
...@@ -125,8 +126,8 @@ pcm_add_vol(void *buffer1, const void *buffer2, size_t size, ...@@ -125,8 +126,8 @@ pcm_add_vol(void *buffer1, const void *buffer2, size_t size,
break; break;
default: default:
g_error("format %s not supported by pcm_add_vol", MPD_ERROR("format %s not supported by pcm_add_vol",
sample_format_to_string(format->format)); sample_format_to_string(format->format));
} }
} }
...@@ -208,8 +209,8 @@ pcm_add(void *buffer1, const void *buffer2, size_t size, ...@@ -208,8 +209,8 @@ pcm_add(void *buffer1, const void *buffer2, size_t size,
break; break;
default: default:
g_error("format %s not supported by pcm_add", MPD_ERROR("format %s not supported by pcm_add",
sample_format_to_string(format->format)); sample_format_to_string(format->format));
} }
} }
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "config.h" #include "config.h"
#include "permission.h" #include "permission.h"
#include "conf.h" #include "conf.h"
#include "mpd_error.h"
#include <glib.h> #include <glib.h>
...@@ -59,7 +60,7 @@ static unsigned parsePermissions(const char *string) ...@@ -59,7 +60,7 @@ static unsigned parsePermissions(const char *string)
} else if (strcmp(temp, PERMISSION_ADMIN_STRING) == 0) { } else if (strcmp(temp, PERMISSION_ADMIN_STRING) == 0) {
permission |= PERMISSION_ADMIN; permission |= PERMISSION_ADMIN;
} else { } else {
g_error("unknown permission \"%s\"", temp); MPD_ERROR("unknown permission \"%s\"", temp);
} }
} }
...@@ -90,7 +91,7 @@ void initPermissions(void) ...@@ -90,7 +91,7 @@ void initPermissions(void)
strchr(param->value, PERMISSION_PASSWORD_CHAR); strchr(param->value, PERMISSION_PASSWORD_CHAR);
if (separator == NULL) if (separator == NULL)
g_error("\"%c\" not found in password string " MPD_ERROR("\"%c\" not found in password string "
"\"%s\", line %i", "\"%s\", line %i",
PERMISSION_PASSWORD_CHAR, PERMISSION_PASSWORD_CHAR,
param->value, param->line); param->value, param->line);
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "idle.h" #include "idle.h"
#include "main.h" #include "main.h"
#include "buffer.h" #include "buffer.h"
#include "mpd_error.h"
#include <glib.h> #include <glib.h>
...@@ -1073,5 +1074,5 @@ void player_create(void) ...@@ -1073,5 +1074,5 @@ void player_create(void)
pc.thread = g_thread_create(player_task, NULL, true, &e); pc.thread = g_thread_create(player_task, NULL, true, &e);
if (pc.thread == NULL) if (pc.thread == NULL)
g_error("Failed to spawn player task: %s", e->message); MPD_ERROR("Failed to spawn player task: %s", e->message);
} }
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "utils.h" #include "utils.h"
#include "conf.h" #include "conf.h"
#include "glib_compat.h" #include "glib_compat.h"
#include "mpd_error.h"
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
...@@ -76,7 +77,7 @@ playlist_plugin_config(const char *plugin_name) ...@@ -76,7 +77,7 @@ playlist_plugin_config(const char *plugin_name)
const char *name = const char *name =
config_get_block_string(param, "name", NULL); config_get_block_string(param, "name", NULL);
if (name == NULL) if (name == NULL)
g_error("playlist configuration without 'plugin' name in line %d", MPD_ERROR("playlist configuration without 'plugin' name in line %d",
param->line); param->line);
if (strcmp(name, plugin_name) == 0) if (strcmp(name, plugin_name) == 0)
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "playlist.h" #include "playlist.h"
#include "conf.h" #include "conf.h"
#include "idle.h" #include "idle.h"
#include "mpd_error.h"
#include <glib.h> #include <glib.h>
...@@ -91,8 +92,8 @@ void replay_gain_global_init(void) ...@@ -91,8 +92,8 @@ void replay_gain_global_init(void)
const struct config_param *param = config_get_param(CONF_REPLAYGAIN); const struct config_param *param = config_get_param(CONF_REPLAYGAIN);
if (param != NULL && !replay_gain_set_mode_string(param->value)) { if (param != NULL && !replay_gain_set_mode_string(param->value)) {
g_error("replaygain value \"%s\" at line %i is invalid\n", MPD_ERROR("replaygain value \"%s\" at line %i is invalid\n",
param->value, param->line); param->value, param->line);
} }
param = config_get_param(CONF_REPLAYGAIN_PREAMP); param = config_get_param(CONF_REPLAYGAIN_PREAMP);
...@@ -102,13 +103,13 @@ void replay_gain_global_init(void) ...@@ -102,13 +103,13 @@ void replay_gain_global_init(void)
float f = strtod(param->value, &test); float f = strtod(param->value, &test);
if (*test != '\0') { if (*test != '\0') {
g_error("Replaygain preamp \"%s\" is not a number at " MPD_ERROR("Replaygain preamp \"%s\" is not a number at "
"line %i\n", param->value, param->line); "line %i\n", param->value, param->line);
} }
if (f < -15 || f > 15) { if (f < -15 || f > 15) {
g_error("Replaygain preamp \"%s\" is not between -15 and" MPD_ERROR("Replaygain preamp \"%s\" is not between -15 and"
"15 at line %i\n", param->value, param->line); "15 at line %i\n", param->value, param->line);
} }
replay_gain_preamp = pow(10, f / 20.0); replay_gain_preamp = pow(10, f / 20.0);
...@@ -121,13 +122,13 @@ void replay_gain_global_init(void) ...@@ -121,13 +122,13 @@ void replay_gain_global_init(void)
float f = strtod(param->value, &test); float f = strtod(param->value, &test);
if (*test != '\0') { if (*test != '\0') {
g_error("Replaygain missing preamp \"%s\" is not a number at " MPD_ERROR("Replaygain missing preamp \"%s\" is not a number at "
"line %i\n", param->value, param->line); "line %i\n", param->value, param->line);
} }
if (f < -15 || f > 15) { if (f < -15 || f > 15) {
g_error("Replaygain missing preamp \"%s\" is not between -15 and" MPD_ERROR("Replaygain missing preamp \"%s\" is not between -15 and"
"15 at line %i\n", param->value, param->line); "15 at line %i\n", param->value, param->line);
} }
replay_gain_missing_preamp = pow(10, f / 20.0); replay_gain_missing_preamp = pow(10, f / 20.0);
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "log.h" #include "log.h"
#include "main.h" #include "main.h"
#include "event_pipe.h" #include "event_pipe.h"
#include "mpd_error.h"
#include <glib.h> #include <glib.h>
...@@ -46,7 +47,7 @@ static void ...@@ -46,7 +47,7 @@ static void
x_sigaction(int signum, const struct sigaction *act) x_sigaction(int signum, const struct sigaction *act)
{ {
if (sigaction(signum, act, NULL) < 0) if (sigaction(signum, act, NULL) < 0)
g_error("sigaction() failed: %s", strerror(errno)); MPD_ERROR("sigaction() failed: %s", strerror(errno));
} }
static void static void
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "tag_pool.h" #include "tag_pool.h"
#include "conf.h" #include "conf.h"
#include "song.h" #include "song.h"
#include "mpd_error.h"
#include <glib.h> #include <glib.h>
#include <assert.h> #include <assert.h>
...@@ -138,8 +139,8 @@ void tag_lib_init(void) ...@@ -138,8 +139,8 @@ void tag_lib_init(void)
type = tag_name_parse_i(c); type = tag_name_parse_i(c);
if (type == TAG_NUM_OF_ITEM_TYPES) if (type == TAG_NUM_OF_ITEM_TYPES)
g_error("error parsing metadata item \"%s\"", MPD_ERROR("error parsing metadata item \"%s\"",
c); c);
ignore_tag_items[type] = false; ignore_tag_items[type] = false;
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "idle.h" #include "idle.h"
#include "stats.h" #include "stats.h"
#include "main.h" #include "main.h"
#include "mpd_error.h"
#include <glib.h> #include <glib.h>
...@@ -93,7 +94,7 @@ spawn_update_task(const char *path) ...@@ -93,7 +94,7 @@ spawn_update_task(const char *path)
update_thr = g_thread_create(update_task, g_strdup(path), TRUE, &e); update_thr = g_thread_create(update_task, g_strdup(path), TRUE, &e);
if (update_thr == NULL) if (update_thr == NULL)
g_error("Failed to spawn update task: %s", e->message); MPD_ERROR("Failed to spawn update task: %s", e->message);
if (++update_task_id > update_task_id_max) if (++update_task_id > update_task_id_max)
update_task_id = 1; update_task_id = 1;
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "config.h" #include "config.h"
#include "zeroconf-internal.h" #include "zeroconf-internal.h"
#include "listen.h" #include "listen.h"
#include "mpd_error.h"
#include <glib.h> #include <glib.h>
...@@ -218,7 +219,7 @@ void init_avahi(const char *serviceName) ...@@ -218,7 +219,7 @@ void init_avahi(const char *serviceName)
g_debug("Initializing interface"); g_debug("Initializing interface");
if (!avahi_is_valid_service_name(serviceName)) if (!avahi_is_valid_service_name(serviceName))
g_error("Invalid zeroconf_name \"%s\"", serviceName); MPD_ERROR("Invalid zeroconf_name \"%s\"", serviceName);
avahiName = avahi_strdup(serviceName); avahiName = avahi_strdup(serviceName);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment