]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/daemon.c
Use the command line utility dropdb instead of the psql command
[bacula/bacula] / bacula / src / lib / daemon.c
index 387a47b1424912ce07d4ede8f3dfcc4c57339ccb..20dc2fdf52fb733cd95b327cb39dfa22d71824eb 100644 (file)
@@ -1,6 +1,8 @@
 /*
  *  daemon.c by Kern Sibbald
  *
+ *   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
@@ -39,7 +41,8 @@ daemon_start()
 {
 #ifndef HAVE_CYGWIN
    int i;
-   int cpid;
+   pid_t cpid;
+   mode_t oldmask;
    /*
     *  Become a daemon.
     */
@@ -54,17 +57,10 @@ daemon_start()
    setsid();
 
    /* In the PRODUCTION system, we close ALL
-    * file descriptors. It is useful
-    * for debugging to leave the standard ones open.
+    * file descriptors except stdin, stdout, and stderr.
     */
-   for (i=sysconf(_SC_OPEN_MAX)-1; i >=0; i--) {
-#ifdef DEBUG
-      if (i != STDIN_FILENO && i != STDOUT_FILENO && i != STDERR_FILENO) {
-        close(i);
-      }
-#else 
+   for (i=sysconf(_SC_OPEN_MAX)-1; i > 2; i--) {
       close(i);
-#endif
    }
 
    /* Move to root directory. For debug we stay
@@ -74,8 +70,13 @@ daemon_start()
    chdir("/");
 #endif
 
-   /* clear any inherited umask */ 
-   umask(0);
+   /* 
+    * Avoid creating files 666 but don't override any
+    * more restrictive mask set by the user.
+    */
+   oldmask = umask(026);
+   oldmask |= 026;
+   umask(oldmask);
 
    Dmsg0(200, "Exit daemon_start\n");
 #endif /* HAVE_CYGWIN */