aboutsummaryrefslogtreecommitdiffstats
path: root/src/listen.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/listen.c')
-rw-r--r--src/listen.c38
1 files changed, 23 insertions, 15 deletions
diff --git a/src/listen.c b/src/listen.c
index d6cade855..3028b9476 100644
--- a/src/listen.c
+++ b/src/listen.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2009 The Music Player Daemon Project
+ * 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
@@ -17,12 +17,13 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include "config.h"
#include "listen.h"
#include "socket_util.h"
#include "client.h"
#include "conf.h"
-#include "utils.h"
-#include "config.h"
+#include "fd_util.h"
+#include "glib_compat.h"
#include <sys/types.h>
#include <sys/stat.h>
@@ -34,6 +35,7 @@
#include <assert.h>
#ifdef WIN32
+#define WINVER 0x0501
#include <ws2tcpip.h>
#include <winsock.h>
#else
@@ -347,7 +349,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 +364,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 +379,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)
@@ -425,12 +434,11 @@ listen_in_event(G_GNUC_UNUSED GIOChannel *source,
{
int listen_fd = GPOINTER_TO_INT(data), fd;
struct sockaddr_storage sa;
- socklen_t sa_length = sizeof(sa);
+ size_t sa_length = sizeof(sa);
- fd = accept(listen_fd, (struct sockaddr*)&sa, &sa_length);
+ fd = accept_cloexec_nonblock(listen_fd, (struct sockaddr*)&sa,
+ &sa_length);
if (fd >= 0) {
- set_nonblocking(fd);
-
client_new(fd, (struct sockaddr*)&sa, sa_length,
get_remote_uid(fd));
} else if (fd < 0 && errno != EINTR) {