Skip to content

glib-unix: Add g_closefrom(), g_fdwalk_set_cloexec()

Simon McVittie requested to merge wip/smcv/closefrom into main
  • glib-unix: Add g_closefrom(), g_fdwalk_set_cloexec()

    These are the same as Linux close_range (lowfd, ~0U, 0) and close_range (lowfd, ~0U, CLOSE_RANGE_CLOEXEC), but portable. Unlike some implementations of BSD closefrom(3), they are async-signal-safe.

    The implementations were moved from the GSpawn code, which already needs all of this functionality anyway, with the exception of set_cloexec() which was copied (leading to some minor duplication, but it's very simple).

    Resolves: #3247 (closed)

  • gspawn: Simplify set_cloexec

    The copy of this function that moved to glib-unix.c still needs to implement the fdwalk-style interface, but this copy does not, allowing us to turn it into a very simple syscall wrapper. Its remaining callers never check for errors, and it never failed anyway, so remove the returned value.

  • tests: Exercise g_fdwalk_set_cloexec() and g_closefrom()

Merge request reports