summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-04-06 18:27:23 +0000
committerHavoc Pennington <hp@redhat.com>2003-04-06 18:27:23 +0000
commit6d54407dbb089dd0b0d8d79189b029c4d82bae81 (patch)
treefb8d1dfceca88d7c63347ab82bb53de6869e5266
parente45e4382274149ca60c11f068ccca719f3598074 (diff)
2003-04-06 Havoc Pennington <hp@pobox.com>
* dbus/dbus-server-unix.c (_dbus_server_new_for_domain_socket): save the domain socket name, and unlink it when we disconnect the server. Means that at least when we exit normally, we won't leave a bunch of junk in /tmp * dbus/dbus-transport-unix.c (_dbus_transport_new_for_domain_socket): code cleanup (nicer memory management). (I was making a real change here but then didn't)
-rw-r--r--ChangeLog12
-rw-r--r--dbus/dbus-server-unix.c52
-rw-r--r--dbus/dbus-transport-unix.c22
3 files changed, 65 insertions, 21 deletions
diff --git a/ChangeLog b/ChangeLog
index ef4c1555..874b5bd6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2003-04-06 Havoc Pennington <hp@pobox.com>
+ * dbus/dbus-server-unix.c (_dbus_server_new_for_domain_socket):
+ save the domain socket name, and unlink it when we disconnect the
+ server. Means that at least when we exit normally, we won't leave
+ a bunch of junk in /tmp
+
+ * dbus/dbus-transport-unix.c
+ (_dbus_transport_new_for_domain_socket): code cleanup (nicer
+ memory management). (I was making a real change here but then
+ didn't)
+
+2003-04-06 Havoc Pennington <hp@pobox.com>
+
* bus/bus.c (bus_context_new): fix wrong handling of
server_data_slot_unref() in the error case.
diff --git a/dbus/dbus-server-unix.c b/dbus/dbus-server-unix.c
index c718923f..0465a2d1 100644
--- a/dbus/dbus-server-unix.c
+++ b/dbus/dbus-server-unix.c
@@ -47,20 +47,23 @@ typedef struct DBusServerUnix DBusServerUnix;
*/
struct DBusServerUnix
{
- DBusServer base; /**< Parent class members. */
- int fd; /**< File descriptor or -1 if disconnected. */
- DBusWatch *watch; /**< File descriptor watch. */
+ DBusServer base; /**< Parent class members. */
+ int fd; /**< File descriptor or -1 if disconnected. */
+ DBusWatch *watch; /**< File descriptor watch. */
+ char *socket_name; /**< Name of domain socket, to unlink if appropriate */
};
static void
unix_finalize (DBusServer *server)
{
DBusServerUnix *unix_server = (DBusServerUnix*) server;
-
- _dbus_server_finalize_base (server);
if (unix_server->watch)
_dbus_watch_unref (unix_server->watch);
+
+ dbus_free (unix_server->socket_name);
+
+ _dbus_server_finalize_base (server);
dbus_free (server);
}
@@ -191,6 +194,13 @@ unix_disconnect (DBusServer *server)
close (unix_server->fd);
unix_server->fd = -1;
+
+ if (unix_server->socket_name != NULL)
+ {
+ DBusString tmp;
+ _dbus_string_init_const (&tmp, unix_server->socket_name);
+ _dbus_delete_file (&tmp, NULL);
+ }
}
static DBusServerVTable unix_vtable = {
@@ -267,8 +277,10 @@ _dbus_server_new_for_domain_socket (const char *path,
DBusError *error)
{
DBusServer *server;
+ DBusServerUnix *unix_server;
int listen_fd;
DBusString address;
+ char *path_copy;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
@@ -281,9 +293,15 @@ _dbus_server_new_for_domain_socket (const char *path,
if (!_dbus_string_append (&address, "unix:path=") ||
!_dbus_string_append (&address, path))
{
- _dbus_string_free (&address);
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
- return NULL;
+ goto failed_0;
+ }
+
+ path_copy = _dbus_strdup (path);
+ if (path_copy == NULL)
+ {
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ goto failed_0;
}
listen_fd = _dbus_listen_unix_socket (path, error);
@@ -291,22 +309,32 @@ _dbus_server_new_for_domain_socket (const char *path,
if (listen_fd < 0)
{
- _dbus_string_free (&address);
- return NULL;
+ _DBUS_ASSERT_ERROR_IS_SET (error);
+ goto failed_1;
}
server = _dbus_server_new_for_fd (listen_fd, &address);
if (server == NULL)
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
- close (listen_fd);
- _dbus_string_free (&address);
- return NULL;
+ goto failed_2;
}
+ unix_server = (DBusServerUnix*) server;
+ unix_server->socket_name = path_copy;
+
_dbus_string_free (&address);
return server;
+
+ failed_2:
+ _dbus_close (listen_fd, NULL);
+ failed_1:
+ dbus_free (path_copy);
+ failed_0:
+ _dbus_string_free (&address);
+
+ return NULL;
}
/**
diff --git a/dbus/dbus-transport-unix.c b/dbus/dbus-transport-unix.c
index 5e37a007..d2bc6d7f 100644
--- a/dbus/dbus-transport-unix.c
+++ b/dbus/dbus-transport-unix.c
@@ -1045,21 +1045,21 @@ _dbus_transport_new_for_domain_socket (const char *path,
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
return NULL;
}
-
+
+ fd = -1;
+
if (!_dbus_string_append (&address, "unix:path=") ||
!_dbus_string_append (&address, path))
{
- _dbus_string_free (&address);
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
- return NULL;
+ goto failed_0;
}
fd = _dbus_connect_unix_socket (path, error);
if (fd < 0)
{
_DBUS_ASSERT_ERROR_IS_SET (error);
- _dbus_string_free (&address);
- return NULL;
+ goto failed_0;
}
_dbus_fd_set_close_on_exec (fd);
@@ -1071,14 +1071,18 @@ _dbus_transport_new_for_domain_socket (const char *path,
if (transport == NULL)
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
- _dbus_string_free (&address);
- _dbus_close (fd, NULL);
- fd = -1;
+ goto failed_1;
}
-
+
_dbus_string_free (&address);
return transport;
+
+ failed_1:
+ _dbus_close (fd, NULL);
+ failed_0:
+ _dbus_string_free (&address);
+ return NULL;
}
/**