[glib/mcatanzaro/gdbus-dir-addresses: 4/7] 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: 4/7] gdbus: Clean up sockets and nonces from filesystem
- Date: Mon, 17 Jun 2019 17:10:35 +0000 (UTC)
commit beac9fe211c1024622433700c138cde677f2054f
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 d504f6251..6bb4b1a4c 100644
--- a/gio/gdbusserver.c
+++ b/gio/gdbusserver.c
@@ -101,6 +101,7 @@ struct _GDBusServer
gchar *client_address;
+ gchar *unix_socket_path;
GSocketListener *listener;
gboolean is_using_listener;
gulong run_signal_handler_id;
@@ -194,10 +195,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);
@@ -768,9 +779,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..3a6c94829 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, 0600), !=, -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]