From 5bfb592d75f2e2ccfc94cb510c5eca755767dfbb Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Wed, 30 Aug 2023 11:33:37 +0200 Subject: supervise-daemon: rename HAVE_CLOSE_RANGE_EXEC to HAVE_CLOSE_RANGE Use HAVE_CLOSE_RANGE to tell if system provides a close_range(2) wrapper, which better explains the purpose. Add a compat inline which returns -1 if close_range is unavailable. --- src/supervise-daemon/supervise-daemon.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/supervise-daemon/supervise-daemon.c') diff --git a/src/supervise-daemon/supervise-daemon.c b/src/supervise-daemon/supervise-daemon.c index 836a1ec7..e36d0314 100644 --- a/src/supervise-daemon/supervise-daemon.c +++ b/src/supervise-daemon/supervise-daemon.c @@ -22,7 +22,7 @@ #define ONE_SECOND 1000000000 #define ONE_MS 1000000 -#ifdef HAVE_CLOSE_RANGE_CLOEXEC +#ifdef HAVE_CLOSE_RANGE /* For close_range() */ # define _GNU_SOURCE #endif @@ -203,6 +203,18 @@ static inline int ioprio_set(int which RC_UNUSED, int who RC_UNUSED, } #endif +#ifndef CLOSE_RANGE_CLOEXEC +# define CLOSE_RANGE_CLOEXEC (1U << 2) +#endif +#ifndef HAVE_CLOSE_RANGE +static inline int close_range(int first RC_UNUSED, + int last RC_UNUSED, + unsigned int flags RC_UNUSED) +{ + return -1; +} +#endif + static void cleanup(void) { free(changeuser); @@ -570,9 +582,7 @@ RC_NORETURN static void child_process(char *exec, char **argv) if (redirect_stderr || rc_yesno(getenv("EINFO_QUIET"))) dup2(stderr_fd, STDERR_FILENO); -#ifdef HAVE_CLOSE_RANGE_CLOEXEC if (close_range(3, UINT_MAX, CLOSE_RANGE_CLOEXEC) < 0) -#endif for (i = getdtablesize() - 1; i >= 3; --i) fcntl(i, F_SETFD, FD_CLOEXEC); cmdline = make_cmdline(argv); -- cgit v1.2.3