gspawn: Add g_spawn_async_with_fds variant

Add a new process spawning function variant which allows the caller
to pass specific file descriptors for stdin, stdout and stderr.
It is otherwise identical to g_spawn_async_with_pipes.

Allow the same fd to be passed in multiple parameters. To make this
workable, the child process logic that closes the fd after the first time
it has been dup2'ed needed tweaking; we now just set those fds to be
closed upon exec using the CLOEXEC flag. Add a test for this case.

This will be used by gnome-shell to avoid performing equivalent
dup2 actions in a child_setup function. Dropping use of child_setup will
enable use of an upcoming optimized process spawning codepath.
This commit is contained in:
Daniel Drake
2018-05-28 10:09:21 -06:00
parent c26558c1b1
commit 3524de16e4
5 changed files with 505 additions and 97 deletions

View File

@@ -1232,6 +1232,7 @@ GSpawnError
G_SPAWN_ERROR
GSpawnFlags
GSpawnChildSetupFunc
g_spawn_async_with_fds
g_spawn_async_with_pipes
g_spawn_async
g_spawn_sync