From 6908a787201b6ad1e814da6ba59afe4b152ed90f Mon Sep 17 00:00:00 2001 From: Marco van Wieringen Date: Thu, 19 Apr 2012 14:05:42 +0200 Subject: [PATCH] Add support for fcntl(fd, F_CLOSEM) to close filedescriptors. --- bacula/autoconf/configure.in | 7 +++++++ bacula/src/lib/daemon.c | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/bacula/autoconf/configure.in b/bacula/autoconf/configure.in index 1e11daae26..b6a9fde2e2 100644 --- a/bacula/autoconf/configure.in +++ b/bacula/autoconf/configure.in @@ -2347,6 +2347,13 @@ AC_CHECK_FUNCS( \ [echo 'configure: cannot find needed function.'; exit 1] ) +AC_CHECK_DECL( + F_CLOSEM, + AC_DEFINE(HAVE_FCNTL_F_CLOSEM), + , + [#include ] +) + AC_CHECK_FUNC(closefrom, [AC_DEFINE(HAVE_CLOSEFROM, 1, [Define to 1 if you have the 'closefrom' function.])]) AC_CHECK_FUNCS(getpagesize, [AC_DEFINE(HAVE_GETPAGESIZE, 1, [Set if have getpagesize])]) AC_CHECK_FUNCS(malloc_trim, [AC_DEFINE(HAVE_MALLOC_TRIM, 1, [Set if have malloc_trim])]) diff --git a/bacula/src/lib/daemon.c b/bacula/src/lib/daemon.c index e736b36217..72b3365caa 100644 --- a/bacula/src/lib/daemon.c +++ b/bacula/src/lib/daemon.c @@ -77,7 +77,15 @@ daemon_start() low_fd = 2; /* don't close debug output */ } -#ifdef HAVE_CLOSEFROM +#if defined(HAVE_FCNTL_F_CLOSEM) + /* + * fcntl(fd, F_CLOSEM) needs the minimum filedescriptor + * to close. the current code sets the last one to keep + * open. So increment it with 1 and use that as argument. + */ + low_fd++; + fcntl(low_fd, F_CLOSEM); +#elif defined(HAVE_CLOSEFROM) /* * closefrom needs the minimum filedescriptor to close. * the current code sets the last one to keep open. -- 2.39.5