Draft: glib-unix: Add convenience API for pipes

Open Simon McVittie requested to merge wip/smcv/auto-unix-pipe into main

Includes !3456 (merged).

Heavily based on code contributed to Steam's steam-runtime-tools under MIT license in https://gitlab.steamos.cloud/steamrt/steam-runtime-tools/-/merge_requests/559, but it occurred to me that this convenience API would be equally useful in other GLib/Unix codebases.

The convenience API could easily be backported into libglnx if desired, but I'd prefer to get it into GLib first.

  • gspawn: Use g_clear_fd() instead of reinventing it

    g_clear_fd() is documented to be async-signal safe whenever the fd is either negative or valid (which it should be here) and the error is NULL (which it always is here).

  • glib-unix: Add convenience API for pipes

    We can't easily use g_autofd with g_unix_open_pipe, because its parameter is an array of two fds that both need closing. Add an inline convenience wrapper providing the obvious semantics.

  • tests: Break out assert_fd_was_closed() into a header

  • tests: Exercise GUnixPipe

  • gspawn: Use GUnixPipe on Unix

Merge request reports