After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 469231 - g_spawn optimization for setting all open fds to CLOEXEC
g_spawn optimization for setting all open fds to CLOEXEC
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2007-08-22 12:56 UTC by Lennart Poettering
Modified: 2007-10-16 05:29 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
The patch (2.31 KB, patch)
2007-08-22 12:56 UTC, Lennart Poettering
accepted-commit_now Details | Review

Description Lennart Poettering 2007-08-22 12:56:03 UTC
g_spawn currently loops through all open and possibly open fds by using sysconf(_SC_OPEN_MAX). That sucks. Because that limit might be immensly high and on normal Linux is already at 1024 by default.

The patch I attached changes this (on Linux at least) by iterating through /proc/self/fd/ and closing every fd listed there. This is measurably more efficient in most cases (i.e. when only very few fds are opened which is the case most of the time)

If /proc is not accessible the code falls back to using the open fd limit. However I also added an optimization here. Instead of using the system limit of open fds we try to use the process limit RLIMIT_NOFILE. On Linux this is practically no improvement, but it might be on other OSes, and it is cleaner anyway.
Comment 1 Lennart Poettering 2007-08-22 12:56:51 UTC
Created attachment 94107 [details] [review]
The patch
Comment 2 Matthias Clasen 2007-10-02 04:32:44 UTC
I guess we should do this.
Comment 3 Matthias Clasen 2007-10-16 05:29:17 UTC
2007-10-16  Matthias Clasen  <mclasen@redhat.com>

        * configure.in: Check for sys/resource.h

        * glib/gspawn.c: Improve the fdwalk implementation on Linux
        to only walk over actually open file descriptors. (#469231,
        Lennart Poettering)