Commit 6d54407d authored by Havoc Pennington's avatar Havoc Pennington

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)
parent e45e4382
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
......
......@@ -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;
}
/**
......
......@@ -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;
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment