From 7edfadb8352d9b25059a7788df97e105d1a6496a Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 20 Aug 2013 20:44:12 +0100 Subject: [PATCH 2/2] Regression tests: also avoid tmpnam() here This is a bit simpler than in production code, because we can just abort on errors that "should never happen". --- tests/lib/file-transfer-chan.c | 12 ++++++++++-- tests/lib/stream-tube-chan.c | 9 ++++++++- tests/lib/util.c | 16 +++++++++++++++- tests/lib/util.h | 1 + 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/tests/lib/file-transfer-chan.c b/tests/lib/file-transfer-chan.c index 8f58943..2afea1d 100644 --- a/tests/lib/file-transfer-chan.c +++ b/tests/lib/file-transfer-chan.c @@ -79,6 +79,7 @@ struct _TpTestsFileTransferChannelPrivate { TpSocketAddressType address_type; GValue *address; gchar *unix_address; + gchar *unix_tmpdir; guint connection_id; TpSocketAccessControl access_control; @@ -160,6 +161,11 @@ dispose (GObject *object) tp_clear_pointer (&self->priv->unix_address, g_free); + if (self->priv->unix_tmpdir != NULL) + g_rmdir (self->priv->unix_tmpdir); + + tp_clear_pointer (&self->priv->unix_tmpdir, g_free); + ((GObjectClass *) tp_tests_file_transfer_channel_parent_class)->dispose ( object); } @@ -481,7 +487,8 @@ file_transfer_provide_file (TpSvcChannelTypeFileTransfer *iface, } self->priv->address = _tp_create_local_socket (address_type, access_control, - &self->priv->service, &self->priv->unix_address, &error); + &self->priv->service, &self->priv->unix_address, + &self->priv->unix_tmpdir, &error); if (self->priv->address == NULL) { @@ -547,7 +554,8 @@ file_transfer_accept_file (TpSvcChannelTypeFileTransfer *iface, } address = _tp_create_local_socket (address_type, access_control, - &self->priv->service, &self->priv->unix_address, &error); + &self->priv->service, &self->priv->unix_address, + &self->priv->unix_tmpdir, &error); tp_g_signal_connect_object (self->priv->service, "incoming", G_CALLBACK (service_incoming_cb), self, 0); diff --git a/tests/lib/stream-tube-chan.c b/tests/lib/stream-tube-chan.c index 95388d0..e2fd2e0 100644 --- a/tests/lib/stream-tube-chan.c +++ b/tests/lib/stream-tube-chan.c @@ -56,6 +56,7 @@ struct _TpTestsStreamTubeChannelPrivate { TpSocketAddressType address_type; GValue *address; gchar *unix_address; + gchar *unix_tmpdir; guint connection_id; TpSocketAccessControl access_control; @@ -211,6 +212,11 @@ dispose (GObject *object) tp_clear_pointer (&self->priv->unix_address, g_free); + if (self->priv->unix_tmpdir != NULL) + g_rmdir (self->priv->unix_tmpdir); + + tp_clear_pointer (&self->priv->unix_tmpdir, g_free); + ((GObjectClass *) tp_tests_stream_tube_channel_parent_class)->dispose ( object); } @@ -482,7 +488,8 @@ stream_tube_accept (TpSvcChannelTypeStreamTube *iface, } address = _tp_create_local_socket (address_type, access_control, - &self->priv->service, &self->priv->unix_address, &error); + &self->priv->service, &self->priv->unix_address, + &self->priv->unix_tmpdir, &error); tp_g_signal_connect_object (self->priv->service, "incoming", G_CALLBACK (service_incoming_cb), self, 0); diff --git a/tests/lib/util.c b/tests/lib/util.c index 9510cb0..022c56b 100644 --- a/tests/lib/util.c +++ b/tests/lib/util.c @@ -338,6 +338,7 @@ _tp_create_local_socket (TpSocketAddressType address_type, TpSocketAccessControl access_control, GSocketService **service, gchar **unix_address, + gchar **unix_tmpdir, GError **error) { gboolean success; @@ -363,7 +364,20 @@ _tp_create_local_socket (TpSocketAddressType address_type, #ifdef HAVE_GIO_UNIX case TP_SOCKET_ADDRESS_TYPE_UNIX: { - address = g_unix_socket_address_new (tmpnam (NULL)); + GError *e = NULL; + gchar *dir = g_dir_make_tmp ("tp-glib-tests.XXXXXX", &e); + gchar *name; + + g_assert_no_error (e); + + name = g_build_filename (dir, "s", NULL); + address = g_unix_socket_address_new (name); + g_free (name); + + if (unix_tmpdir != NULL) + *unix_tmpdir = dir; + else + g_free (dir); break; } #endif diff --git a/tests/lib/util.h b/tests/lib/util.h index ce19d66..18d8687 100644 --- a/tests/lib/util.h +++ b/tests/lib/util.h @@ -69,6 +69,7 @@ GValue *_tp_create_local_socket (TpSocketAddressType address_type, TpSocketAccessControl access_control, GSocketService **service, gchar **unix_address, + gchar **unix_tmpdir, GError **error); void _tp_destroy_socket_control_list (gpointer data); -- 1.8.4.rc3