[glib/gdbus-daemon: 5/6] gdbusserver: When listening to non-abstract unix socket, remove existing socket



commit 7c85b894db34c529eb7a2824d4ec3621ae5c2288
Author: Alexander Larsson <alexl redhat com>
Date:   Mon Apr 16 10:49:39 2012 +0200

    gdbusserver: When listening to non-abstract unix socket, remove existing socket
    
    This is what libdbus does in _dbus_listen_unix_socket, and without it we get
    EADDRINUSE in the test suite when using gdbus-daemon.

 gio/gdbusserver.c |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)
---
diff --git a/gio/gdbusserver.c b/gio/gdbusserver.c
index 5e7dd85..9e5fa7e 100644
--- a/gio/gdbusserver.c
+++ b/gio/gdbusserver.c
@@ -32,6 +32,7 @@
 #include <io.h>
 #endif
 
+#include <glib/gstdio.h>
 #include "giotypes.h"
 #include "gioerror.h"
 #include "gdbusaddress.h"
@@ -655,6 +656,13 @@ try_unix (GDBusServer  *server,
 
   if (path != NULL)
     {
+      struct stat sb;
+
+      /* This is what libdbus does in _dbus_listen_unix_socket, so we do it too */
+      if (g_stat (path, &sb) == 0 &&
+	  S_ISSOCK (sb.st_mode))
+	unlink (path);
+
       address = g_unix_socket_address_new (path);
     }
   else if (tmpdir != NULL)
@@ -675,7 +683,17 @@ try_unix (GDBusServer  *server,
                                                        -1,
                                                        G_UNIX_SOCKET_ADDRESS_ABSTRACT);
       else
-        address = g_unix_socket_address_new (s->str);
+	{
+	  struct stat sb;
+
+	  /* This is what libdbus does in _dbus_listen_unix_socket, so we do it too */
+	  if (g_stat (s->str, &sb) == 0 &&
+	      S_ISSOCK (sb.st_mode))
+	    unlink (s->str);
+
+	  address = g_unix_socket_address_new (s->str);
+	}
+
       g_string_free (s, TRUE);
 
       local_error = NULL;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]