aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-09-24 21:40:04 +0200
committerMax Kellermann <max@duempel.org>2009-09-24 21:40:04 +0200
commit308b3f2337f100b5d27fa2af50bf929caff4a7d4 (patch)
treed85afd52f91b2e54870aac4ef2b55135a604713d
parent1e561079676a4774afa8b9c405d98001915322f3 (diff)
downloadmpd-308b3f2337f100b5d27fa2af50bf929caff4a7d4.tar.gz
mpd-308b3f2337f100b5d27fa2af50bf929caff4a7d4.tar.xz
mpd-308b3f2337f100b5d27fa2af50bf929caff4a7d4.zip
listen: handle fatal errors with GError
Don't call g_error(), which will abort the process and dump core.
Diffstat (limited to '')
-rw-r--r--src/listen.c23
-rw-r--r--src/listen.h7
-rw-r--r--src/main.c9
3 files changed, 29 insertions, 10 deletions
diff --git a/src/listen.c b/src/listen.c
index 98108d9da..4728e7c7a 100644
--- a/src/listen.c
+++ b/src/listen.c
@@ -347,7 +347,8 @@ listen_add_config_param(unsigned int port,
}
}
-void listen_global_init(void)
+bool
+listen_global_init(GError **error_r)
{
int port = config_get_positive(CONF_PORT, DEFAULT_PORT);
const struct config_param *param =
@@ -361,10 +362,12 @@ void listen_global_init(void)
do {
success = listen_add_config_param(port, param, &error);
- if (!success)
- g_error("Failed to listen on %s (line %i): %s",
- param->value, param->line,
- error->message);
+ if (!success) {
+ g_propagate_prefixed_error(error_r, error,
+ "Failed to listen on %s (line %i): ",
+ param->value, param->line);
+ return false;
+ }
param = config_get_next_param(CONF_BIND_TO_ADDRESS,
param);
@@ -374,12 +377,16 @@ void listen_global_init(void)
configured port on all interfaces */
success = listen_add_port(port, &error);
- if (!success)
- g_error("Failed to listen on *:%d: %s",
- port, error->message);
+ if (!success) {
+ g_propagate_prefixed_error(error_r, error,
+ "Failed to listen on *:%d: ",
+ port);
+ return false;
+ }
}
listen_port = port;
+ return true;
}
void listen_global_finish(void)
diff --git a/src/listen.h b/src/listen.h
index 63253fc53..9f55edb88 100644
--- a/src/listen.h
+++ b/src/listen.h
@@ -20,9 +20,14 @@
#ifndef MPD_LISTEN_H
#define MPD_LISTEN_H
+#include <glib.h>
+
+#include <stdbool.h>
+
extern int listen_port;
-void listen_global_init(void);
+bool
+listen_global_init(GError **error_r);
void listen_global_finish(void);
diff --git a/src/main.c b/src/main.c
index 775ae9a72..0d7cbf1ed 100644
--- a/src/main.c
+++ b/src/main.c
@@ -273,6 +273,8 @@ int main(int argc, char *argv[])
struct options options;
clock_t start;
bool create_db;
+ GError *error = NULL;
+ bool success;
daemonize_close_stdin();
@@ -301,7 +303,12 @@ int main(int argc, char *argv[])
tag_lib_init();
log_init(options.verbose, options.log_stderr);
- listen_global_init();
+ success = listen_global_init(&error);
+ if (!success) {
+ g_warning("%s", error->message);
+ g_error_free(error);
+ return EXIT_FAILURE;
+ }
daemonize_set_user();