Skip to content

Commit

Permalink
xdp-utils: Allow passing an fd the to spawned child process
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jsparber committed Aug 27, 2024
1 parent fea6b28 commit 20634c6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/xdp-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,16 +432,18 @@ 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);

return output;
}

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

Expand Down
4 changes: 3 additions & 1 deletion src/xdp-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 20634c6

Please sign in to comment.