From 010296562bf19b52c744976ef7da905ab42731d4 Mon Sep 17 00:00:00 2001 From: Thomas Themel Date: Fri, 27 Aug 2010 11:35:14 +0200 Subject: [PATCH] Set SO_REUSEADDR when creating a TCP listen socket on Unix to avoid EADDRINUSE when restarting a dbus-daemon with TCP listeners. --- dbus/dbus-sysdeps-unix.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index e859ec6..b07690f 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -1314,7 +1314,7 @@ _dbus_listen_tcp_socket (const char *host, tmp = ai; while (tmp) { - int fd = -1, *newlisten_fd; + int fd = -1, *newlisten_fd, iopt; if (!_dbus_open_socket (&fd, tmp->ai_family, SOCK_STREAM, 0, error)) { _DBUS_ASSERT_ERROR_IS_SET(error); @@ -1322,6 +1322,9 @@ _dbus_listen_tcp_socket (const char *host, } _DBUS_ASSERT_ERROR_IS_CLEAR(error); + iopt=1; + setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &iopt, sizeof(iopt)); + if (bind (fd, (struct sockaddr*) tmp->ai_addr, tmp->ai_addrlen) < 0) { saved_errno = errno; -- 1.7.1