/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2008 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-2011 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
/*
* daemon.c by Kern Sibbald 2000
*
- * Version $Id$
- *
* This code is inspired by the Prentice Hall book
* "Unix Network Programming" by W. Richard Stevens
* and later updated from his book "Advanced Programming
{
#if !defined(HAVE_WIN32)
int i;
+ int fd;
pid_t cpid;
mode_t oldmask;
#ifdef DEVELOPER
if (debug_level > 0) {
low_fd = 2; /* don't close debug output */
}
+
+#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.
+ * 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.
* send total garbage to our socket.
*
*/
- int fd;
fd = open("/dev/null", O_RDONLY, 0644);
if (fd > 2) {
close(fd);