X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gio%2Fgtestdbus.c;h=4af270be0fb32e625047df3e6e60c2d22e18da51;hb=2a2b11b1bb6c702d6b2ef1c37524a57688a94a4e;hp=012c7e010bf8508824839cc993156461365bf07e;hpb=111803030d54b192ca1edd25bbde90130eaff2a9;p=platform%2Fupstream%2Fglib.git
diff --git a/gio/gtestdbus.c b/gio/gtestdbus.c
index 012c7e0..4af270b 100644
--- a/gio/gtestdbus.c
+++ b/gio/gtestdbus.c
@@ -338,13 +338,13 @@ _g_test_watcher_remove_pid (GPid pid)
* code tree.
*
* The first thing you will need is a separate service description file for the
- * D-Bus daemon. Typically a services subdirectory of
- * your tests directory is a good place to put this file.
+ * D-Bus daemon. Typically a `services` subdirectory of your `tests` directory
+ * is a good place to put this file.
*
* The service file should list your service along with an absolute path to the
* uninstalled service executable in your source tree. Using autotools we would
- * achieve this by adding a file such as my-server.service.in
- * in the services directory and have it processed by configure.
+ * achieve this by adding a file such as `my-server.service.in` in the services
+ * directory and have it processed by configure.
* |[
* [D-BUS Service]
* Name=org.gtk.GDBus.Examples.ObjectManager
@@ -361,7 +361,8 @@ _g_test_watcher_remove_pid (GPid pid)
* you can proceed to set up a GTest fixture using the #GTestDBus scaffolding.
*
* An example of a test fixture for D-Bus services can be found
- * here: gdbus-test-fixture.c
+ * here:
+ * [gdbus-test-fixture.c](https://git.gnome.org/browse/glib/tree/gio/tests/gdbus-test-fixture.c)
*
* Note that these examples only deal with isolating the D-Bus aspect of your
* service. To successfully run isolated unit tests on your service you may need
@@ -417,6 +418,7 @@ struct _GTestDBusPrivate
GTestDBusFlags flags;
GPtrArray *service_dirs;
GPid bus_pid;
+ gint bus_stdout_fd;
gchar *bus_address;
gboolean up;
};
@@ -565,13 +567,12 @@ write_config_file (GTestDBus *self)
" \n"
"\n");
+ close (fd);
g_file_set_contents (path, contents->str, contents->len, &error);
g_assert_no_error (error);
g_string_free (contents, TRUE);
- close (fd);
-
return path;
}
@@ -581,8 +582,8 @@ start_daemon (GTestDBus *self)
const gchar *argv[] = {"dbus-daemon", "--print-address", "--config-file=foo", NULL};
gchar *config_path;
gchar *config_arg;
- gint stdout_fd;
GIOChannel *channel;
+ gint stdout_fd2;
gsize termpos;
GError *error = NULL;
@@ -607,15 +608,21 @@ start_daemon (GTestDBus *self)
NULL,
&self->priv->bus_pid,
NULL,
- &stdout_fd,
+ &self->priv->bus_stdout_fd,
NULL,
&error);
g_assert_no_error (error);
_g_test_watcher_add_pid (self->priv->bus_pid);
- /* Read bus address from daemon' stdout */
- channel = g_io_channel_unix_new (stdout_fd);
+ /* Read bus address from daemon' stdout. We have to be careful to avoid
+ * closing the FD, as it is passed to any D-Bus service activated processes,
+ * and if we close it, they will get a SIGPIPE and die when they try to write
+ * to their stdout. */
+ stdout_fd2 = dup (self->priv->bus_stdout_fd);
+ g_assert_cmpint (stdout_fd2, >=, 0);
+ channel = g_io_channel_unix_new (stdout_fd2);
+
g_io_channel_read_line (channel, &self->priv->bus_address, NULL,
&termpos, &error);
g_assert_no_error (error);
@@ -659,6 +666,8 @@ stop_daemon (GTestDBus *self)
_g_test_watcher_remove_pid (self->priv->bus_pid);
g_spawn_close_pid (self->priv->bus_pid);
self->priv->bus_pid = 0;
+ close (self->priv->bus_stdout_fd);
+ self->priv->bus_stdout_fd = -1;
g_free (self->priv->bus_address);
self->priv->bus_address = NULL;