]> git.sur5r.net Git - bacula/bacula/commitdiff
Use closefrom if available instead of trying to close fds ourself.
authorMarco van Wieringen <mvw@planets.elm.net>
Thu, 19 Apr 2012 12:05:34 +0000 (14:05 +0200)
committerKern Sibbald <kern@sibbald.com>
Mon, 28 May 2012 09:09:31 +0000 (11:09 +0200)
bacula/autoconf/config.h.in
bacula/autoconf/configure.in
bacula/src/lib/daemon.c

index dc367ddcc92eaa1af21538d5d2c0ad237c7fc4c6..8a75168460b93f1ef82b3b28bdbfb35706a8ddd5 100644 (file)
 /* Define to 1 if you have the `chflags' function. */
 #undef HAVE_CHFLAGS
 
+/* Define to 1 if you have the 'closefrom' function. */
+#undef HAVE_CLOSEFROM
+
 /* Set if Bacula conio support enabled */
 #undef HAVE_CONIO
 
index fb9bb57487580ab5a6c6f72eaed5ff8bd0c76639..1e11daae260e0e2a6c31fe496c0f442921f95309 100644 (file)
@@ -2347,6 +2347,7 @@ AC_CHECK_FUNCS( \
    [echo 'configure: cannot find needed function.'; exit 1]
 )
 
+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])])
 
index 3a25812c1ecdfeff1d240a890f8793cc93f9332c..e736b362179d44391226c9fb4340c7a70bbcec41 100644 (file)
@@ -47,6 +47,7 @@ daemon_start()
 {
 #if !defined(HAVE_WIN32)
    int i;
+   int fd;
    pid_t cpid;
    mode_t oldmask;
 #ifdef DEVELOPER
@@ -75,9 +76,20 @@ daemon_start()
    if (debug_level > 0) {
       low_fd = 2;                     /* don't close debug output */
    }
+
+#ifdef HAVE_CLOSEFROM
+   /*
+    * closefrom 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++;
+   closefrom(low_fd);
+#else
    for (i=sysconf(_SC_OPEN_MAX)-1; i > low_fd; i--) {
       close(i);
    }
+#endif
 
    /* Move to root directory. For debug we stay
     * in current directory so dumps go there.
@@ -102,7 +114,6 @@ daemon_start()
     *  send total garbage to our socket.
     *
     */
-   int fd;
    fd = open("/dev/null", O_RDONLY, 0644);
    if (fd > 2) {
       close(fd);