tests: Add e flag to fdopen() calls in gsubprocess tests

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 <pwithnall@gnome.org>
This commit is contained in:
Philip Withnall
2025-03-20 12:30:08 +00:00
parent f9a7ac11f5
commit ac2ecb5a43

View File

@@ -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));