mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-20 15:48:54 +02:00
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
This commit is contained in:
@@ -101,6 +101,7 @@ struct _GDBusServer
|
|||||||
|
|
||||||
gchar *client_address;
|
gchar *client_address;
|
||||||
|
|
||||||
|
gchar *unix_socket_path;
|
||||||
GSocketListener *listener;
|
GSocketListener *listener;
|
||||||
gboolean is_using_listener;
|
gboolean is_using_listener;
|
||||||
gulong run_signal_handler_id;
|
gulong run_signal_handler_id;
|
||||||
@@ -194,10 +195,20 @@ g_dbus_server_finalize (GObject *object)
|
|||||||
memset (server->nonce, '\0', 16);
|
memset (server->nonce, '\0', 16);
|
||||||
g_free (server->nonce);
|
g_free (server->nonce);
|
||||||
}
|
}
|
||||||
/* we could unlink the nonce file but I don't
|
|
||||||
* think it's really worth the effort/risk
|
if (server->unix_socket_path)
|
||||||
*/
|
{
|
||||||
g_free (server->nonce_file);
|
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);
|
g_main_context_unref (server->main_context_at_construction);
|
||||||
|
|
||||||
@@ -768,9 +779,12 @@ try_unix (GDBusServer *server,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case G_UNIX_SOCKET_ADDRESS_PATH:
|
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)));
|
const char *address_path = g_unix_socket_address_get_path (G_UNIX_SOCKET_ADDRESS (address));
|
||||||
break;
|
server->client_address = g_strdup_printf ("unix:path=%s", address_path);
|
||||||
|
server->unix_socket_path = g_strdup (address_path);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
g_assert_not_reached ();
|
g_assert_not_reached ();
|
||||||
|
@@ -1351,12 +1351,16 @@ test_nonce_tcp (void)
|
|||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
g_assert (c == NULL);
|
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_dbus_server_stop (server);
|
||||||
g_object_unref (server);
|
g_object_unref (server);
|
||||||
server = NULL;
|
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_main_loop_quit (service_loop);
|
||||||
g_thread_join (service_thread);
|
g_thread_join (service_thread);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user