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.
*/
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);
}
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 = {
DBusError *error)
{
DBusServer *server;
+ DBusServerUnix *unix_server;
int listen_fd;
DBusString address;
+ char *path_copy;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
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);
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;
}
/**
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);
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;
}
/**