mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-25 02:18:55 +02:00
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:
@@ -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));
|
||||
|
Reference in New Issue
Block a user