[glib/mcatanzaro/gdbus-dir-addresses] gdbus: Clean up sockets and nonces from filesystem
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/mcatanzaro/gdbus-dir-addresses] gdbus: Clean up sockets and nonces from filesystem
- Date: Wed, 12 Jun 2019 21:13:42 +0000 (UTC)
commit bc285561a055490b9dc21a0cd903466be8c9d686
Author: Michael Catanzaro <mcatanzaro igalia com>
Date: Wed Jun 12 13:55:06 2019 -0500
gdbus: Clean up sockets and nonces from filesystem
When we close the GDBusServer, it should remove any non-abstract Unix
sockets or TCP nonce files it created from the filesystem.
Fixes #1808
gio/gdbusserver.c | 28 +++++++++++++++++++++-------
gio/tests/gdbus-peer.c | 6 +++++-
2 files changed, 26 insertions(+), 8 deletions(-)
---
diff --git a/gio/gdbusserver.c b/gio/gdbusserver.c
index 10f179a47..4379bc28b 100644
--- a/gio/gdbusserver.c
+++ b/gio/gdbusserver.c
@@ -96,6 +96,7 @@ struct _GDBusServer
gchar *client_address;
+ gchar *unix_socket_path;
GSocketListener *listener;
gboolean is_using_listener;
gulong run_signal_handler_id;
@@ -189,10 +190,20 @@ g_dbus_server_finalize (GObject *object)
memset (server->nonce, '\0', 16);
g_free (server->nonce);
}
- /* we could unlink the nonce file but I don't
- * think it's really worth the effort/risk
- */
- g_free (server->nonce_file);
+
+ if (server->unix_socket_path)
+ {
+ if (g_unlink (server->unix_socket_path) != 0)
+ g_warning ("Failed to delete %s: %s", server->unix_socket_path, g_strerror (errno));
+ g_free (server->unix_socket_path);
+ }
+
+ if (server->nonce_file)
+ {
+ if (g_unlink (server->nonce_file) != 0)
+ g_warning ("Failed to delete %s: %s", server->nonce_file, g_strerror (errno));
+ g_free (server->nonce_file);
+ }
g_main_context_unref (server->main_context_at_construction);
@@ -759,9 +770,12 @@ try_unix (GDBusServer *server,
break;
case G_UNIX_SOCKET_ADDRESS_PATH:
- server->client_address = g_strdup_printf ("unix:path=%s",
- g_unix_socket_address_get_path
(G_UNIX_SOCKET_ADDRESS (address)));
- break;
+ {
+ const char *address_path = g_unix_socket_address_get_path (G_UNIX_SOCKET_ADDRESS (address));
+ server->client_address = g_strdup_printf ("unix:path=%s", address_path);
+ server->unix_socket_path = g_strdup (address_path);
+ break;
+ }
default:
g_assert_not_reached ();
diff --git a/gio/tests/gdbus-peer.c b/gio/tests/gdbus-peer.c
index c21b9e9f2..f100230a6 100644
--- a/gio/tests/gdbus-peer.c
+++ b/gio/tests/gdbus-peer.c
@@ -1351,12 +1351,16 @@ test_nonce_tcp (void)
g_error_free (error);
g_assert (c == NULL);
- g_free (nonce_file);
+ /* Recreate the nonce-file so we can ensure the server deletes it when stopped. */
+ g_assert_cmpint (g_creat (nonce_file, O_RDWR), !=, -1);
g_dbus_server_stop (server);
g_object_unref (server);
server = NULL;
+ g_assert_false (g_file_test (nonce_file, G_FILE_TEST_EXISTS));
+ g_free (nonce_file);
+
g_main_loop_quit (service_loop);
g_thread_join (service_thread);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]