This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=6c304121b82d43d2e9968fa6cc59c2b2a8563e2f

commit 6c304121b82d43d2e9968fa6cc59c2b2a8563e2f
Author: Guillem Jover <[email protected]>
AuthorDate: Fri Sep 13 06:15:44 2024 +0200

    s-s-d: Try to use close_range() if present to implement closefrom()
    
    If the system has close_range() use it, and fallback to the open coded
    closing, in case the function was present at build time but not
    implemented at run-time, or it failed for whatever reason.
    
    Proposed-by: Mix <[email protected]>
    Changelog: internal
---
 configure.ac              | 1 +
 utils/start-stop-daemon.c | 5 +++++
 2 files changed, 6 insertions(+)

diff --git a/configure.ac b/configure.ac
index 761663b17..987f9efd4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -214,6 +214,7 @@ AC_CHECK_FUNCS([\
   setsid \
   getdtablesize \
   closefrom \
+  close_range \
   getprocs64 \
   getprogname \
   getexecname \
diff --git a/utils/start-stop-daemon.c b/utils/start-stop-daemon.c
index 9e18ca7ad..d11ad2930 100644
--- a/utils/start-stop-daemon.c
+++ b/utils/start-stop-daemon.c
@@ -513,6 +513,11 @@ closefrom(int lowfd)
        long maxfd = get_open_fd_max();
        int i;
 
+#ifdef HAVE_CLOSE_RANGE
+       if (close_range(lowfd, maxfd, 0) == 0)
+               return;
+#endif
+
        for (i = maxfd - 1; i >= lowfd; --i)
                close(i);
 }

-- 
Dpkg.Org's dpkg

Reply via email to