]> 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 6613b7f6aa82eb35671cdbeed140838c147b0a22..20dc2fdf52fb733cd95b327cb39dfa22d71824eb 100644 (file)
@@ -41,7 +41,8 @@ daemon_start()
 {
 #ifndef HAVE_CYGWIN
    int i;
-   int cpid;
+   pid_t cpid;
+   mode_t oldmask;
    /*
     *  Become a daemon.
     */
@@ -56,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
@@ -76,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 */