From 20634c6bd18948444b831862ad275bfdb8ca6632 Mon Sep 17 00:00:00 2001 From: Julian Sparber Date: Tue, 9 Jul 2024 17:33:07 +0200 Subject: [PATCH] xdp-utils: Allow passing an fd the to spawned child process This allows to use the same spawn methods to be used also by the icon validator, which in a future commit will use it and switch to using fds instead of temp files. --- src/xdp-utils.c | 11 ++++++++--- src/xdp-utils.h | 4 +++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/xdp-utils.c b/src/xdp-utils.c index 8b335561b..169df53e3 100644 --- a/src/xdp-utils.c +++ b/src/xdp-utils.c @@ -432,7 +432,7 @@ xdp_spawn (GError **error, g_ptr_array_add (args, NULL); va_end (ap); - output = xdp_spawnv ((const gchar * const *) args->pdata, error); + output = xdp_spawn_full ((const gchar * const *) args->pdata, -1, -1, error); g_ptr_array_free (args, TRUE); @@ -440,8 +440,10 @@ xdp_spawn (GError **error, } gchar * -xdp_spawnv (const gchar * const *argv, - GError **error) +xdp_spawn_full (const gchar * const *argv, + int source_fd, + int target_fd, + GError **error) { g_autoptr(GSubprocessLauncher) launcher = NULL; g_autoptr(GSubprocess) subp = NULL; @@ -453,6 +455,9 @@ xdp_spawnv (const gchar * const *argv, launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE); + if (source_fd != -1) + g_subprocess_launcher_take_fd (launcher, source_fd, target_fd); + commandline = xdp_quote_argv ((const char **)argv); g_debug ("Running: %s", commandline); diff --git a/src/xdp-utils.h b/src/xdp-utils.h index 85c72a23a..4b8304a85 100644 --- a/src/xdp-utils.h +++ b/src/xdp-utils.h @@ -125,7 +125,9 @@ char * xdp_quote_argv (const char *argv[]); char * xdp_spawn (GError **error, const gchar *argv0, ...) G_GNUC_NULL_TERMINATED; -char * xdp_spawnv (const gchar * const *argv, +char * xdp_spawn_full (const gchar * const *argv, + int source_fd, + int target_fd, GError **error); char * xdp_canonicalize_filename (const char *path);