diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2021-10-29 10:32:52 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2021-10-29 10:32:52 +0900 |
commit | 88bd743b4dd50e84d9c2970ff30393474af3f7bf (patch) | |
tree | a218eddccce99e5e0c70ff29a17a461d7b6e9fe2 /gio/tests/gsubprocess.c | |
parent | dede7e78ca86551aa696e2b3c7bf14f242c103d8 (diff) | |
download | glib-88bd743b4dd50e84d9c2970ff30393474af3f7bf.tar.gz glib-88bd743b4dd50e84d9c2970ff30393474af3f7bf.tar.bz2 glib-88bd743b4dd50e84d9c2970ff30393474af3f7bf.zip |
Imported Upstream version 2.67.5upstream/2.67.5
Diffstat (limited to 'gio/tests/gsubprocess.c')
-rw-r--r-- | gio/tests/gsubprocess.c | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/gio/tests/gsubprocess.c b/gio/tests/gsubprocess.c index 3c248e610..7e22678ec 100644 --- a/gio/tests/gsubprocess.c +++ b/gio/tests/gsubprocess.c @@ -1494,23 +1494,44 @@ test_subprocess_launcher_close (void) GSubprocessLauncher *launcher; GSubprocess *proc; GPtrArray *args; - int fd; + int fd, fd2; gboolean is_open; - fd = dup(0); + /* Open two arbitrary FDs. One of them, @fd, will be transferred to the + * launcher, and the other’s FD integer will be used as its target FD, giving + * the mapping `fd → fd2` if a child process were to be spawned. + * + * The launcher will then be closed, which should close @fd but *not* @fd2, + * as the value of @fd2 is only valid as an FD in a child process. (A child + * process is not actually spawned in this test.) + */ + fd = dup (0); + fd2 = dup (0); launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_NONE); - g_subprocess_launcher_take_fd (launcher, fd, fd); + g_subprocess_launcher_take_fd (launcher, fd, fd2); + is_open = fcntl (fd, F_GETFD) != -1; g_assert_true (is_open); + is_open = fcntl (fd2, F_GETFD) != -1; + g_assert_true (is_open); + g_subprocess_launcher_close (launcher); + is_open = fcntl (fd, F_GETFD) != -1; g_assert_false (is_open); + is_open = fcntl (fd2, F_GETFD) != -1; + g_assert_true (is_open); + + /* Now test that actually trying to spawn the child gives %G_IO_ERROR_CLOSED, + * as g_subprocess_launcher_close() has been called. */ args = get_test_subprocess_args ("cat", NULL); proc = g_subprocess_launcher_spawnv (launcher, (const gchar * const *) args->pdata, error); g_ptr_array_free (args, TRUE); g_assert_null (proc); g_assert_error (local_error, G_IO_ERROR, G_IO_ERROR_CLOSED); g_clear_error (error); + + close (fd2); g_object_unref (launcher); } |