From ac2ecb5a437c58c34548adc570a2d50530bad5cb Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 20 Mar 2025 12:30:08 +0000 Subject: [PATCH] tests: Add `e` flag to fdopen() calls in gsubprocess tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unlike the previous commit, there is no `g_fdopen()` wrapper where we can add cross-platform support for this. I’m not adding that now just for `O_CLOEXEC` support for these two calls, so pass the flag locally for now. If someone wanted to add a `g_fdopen()` wrapper in future, the `GLIB_FD_CLOEXEC` here could be refactored easily. Signed-off-by: Philip Withnall --- gio/tests/gsubprocess-testprog.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gio/tests/gsubprocess-testprog.c b/gio/tests/gsubprocess-testprog.c index 05fc526f3..b61ccc261 100644 --- a/gio/tests/gsubprocess-testprog.c +++ b/gio/tests/gsubprocess-testprog.c @@ -124,6 +124,12 @@ sleep_forever_mode (int argc, return 0; } +#ifdef G_OS_UNIX +#define GLIB_FD_CLOEXEC "e" +#else +#define GLIB_FD_CLOEXEC "" +#endif + static int write_to_fds (int argc, char **argv) { @@ -132,7 +138,7 @@ write_to_fds (int argc, char **argv) for (i = 2; i < argc; i++) { int fd = atoi (argv[i]); - FILE *f = fdopen (fd, "w"); + FILE *f = fdopen (fd, "w" GLIB_FD_CLOEXEC); const char buf[] = "hello world\n"; size_t bytes_written; @@ -170,7 +176,7 @@ read_from_fd (int argc, char **argv) return 1; } - f = fdopen (fd, "r"); + f = fdopen (fd, "r" GLIB_FD_CLOEXEC); if (f == NULL) { g_warning ("Failed to open fd %d: %s", fd, g_strerror (errno));