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=394a55833f1e3a25cf1720cf811d44dfde65893a commit 394a55833f1e3a25cf1720cf811d44dfde65893a Author: Guillem Jover <[email protected]> AuthorDate: Fri Sep 13 06:15:44 2024 +0200 s-s-d: Refactor closefrom() and use it only if the system lacks it Move the code into a function that behaves like the BSD system one, and use if the system does not provide it. Changelog: internal --- configure.ac | 1 + utils/start-stop-daemon.c | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 3f1a86362..761663b17 100644 --- a/configure.ac +++ b/configure.ac @@ -213,6 +213,7 @@ AC_CHECK_FUNCS([\ AC_CHECK_FUNCS([\ setsid \ getdtablesize \ + closefrom \ getprocs64 \ getprogname \ getexecname \ diff --git a/utils/start-stop-daemon.c b/utils/start-stop-daemon.c index 8899f0c03..9e18ca7ad 100644 --- a/utils/start-stop-daemon.c +++ b/utils/start-stop-daemon.c @@ -496,6 +496,7 @@ parse_unsigned(const char *string, int base, int *value_r) return 0; } +#ifndef HAVE_CLOSEFROM static long get_open_fd_max(void) { @@ -506,6 +507,17 @@ get_open_fd_max(void) #endif } +static void +closefrom(int lowfd) +{ + long maxfd = get_open_fd_max(); + int i; + + for (i = maxfd - 1; i >= lowfd; --i) + close(i); +} +#endif + #ifndef HAVE_SETSID static void detach_controlling_tty(void) @@ -2660,13 +2672,10 @@ do_start(int argc, char **argv) dup2(output_fd, 2); /* stderr */ } if (background && close_io) { - int i; - dup2(devnull_fd, 0); /* stdin */ - /* Now close all extra fds. */ - for (i = get_open_fd_max() - 1; i >= 3; --i) - close(i); + /* Now close all extra fds. */ + closefrom(3); } execv(startas, argv); fatale("unable to start %s", startas); -- Dpkg.Org's dpkg

