summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-server-unix.c
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 /dbus/dbus-server-unix.c
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)
Diffstat (limited to 'dbus/dbus-server-unix.c')
-rw-r--r--dbus/dbus-server-unix.c52
1 files changed, 40 insertions, 12 deletions
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;
}
/**