]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
global/global_init: close stdout in postfork_finish, not start 20681/head
authorSage Weil <sage@redhat.com>
Fri, 2 Mar 2018 03:52:33 +0000 (21:52 -0600)
committerSage Weil <sage@redhat.com>
Sun, 4 Mar 2018 21:31:55 +0000 (15:31 -0600)
During the interval where we have done our prefork but not actually
detached from the parent to daemonize, we may still want to send output
to stdout.

Signed-off-by: Sage Weil <sage@redhat.com>
src/global/global_init.cc

index 08e6d1035de14544aae51b2373124789a3b8c986..9855f370882fc3fb72c05af6c5218aef87f277d4 100644 (file)
@@ -413,13 +413,6 @@ void global_init_postfork_start(CephContext *cct)
         << err << dendl;
     exit(1);
   }
-  VOID_TEMP_FAILURE_RETRY(close(STDOUT_FILENO));
-  if (open("/dev/null", O_RDONLY) < 0) {
-    int err = errno;
-    derr << "global_init_daemonize: open(/dev/null) failed: error "
-        << err << dendl;
-    exit(1);
-  }
 
   const md_config_t *conf = cct->_conf;
   if (pidfile_write(conf) < 0)
@@ -434,8 +427,8 @@ void global_init_postfork_start(CephContext *cct)
 
 void global_init_postfork_finish(CephContext *cct)
 {
-  /* We only close stderr once the caller decides the daemonization
-   * process is finished.  This way we can allow error messages to be
+  /* We only close stdout+stderr once the caller decides the daemonization
+   * process is finished.  This way we can allow error or other messages to be
    * propagated in a manner that the user is able to see.
    */
   if (!(cct->get_init_flags() & CINIT_FLAG_NO_CLOSE_STDERR)) {
@@ -446,6 +439,15 @@ void global_init_postfork_finish(CephContext *cct)
       exit(1);
     }
   }
+
+  VOID_TEMP_FAILURE_RETRY(close(STDOUT_FILENO));
+  if (open("/dev/null", O_RDONLY) < 0) {
+    int err = errno;
+    derr << "global_init_daemonize: open(/dev/null) failed: error "
+        << err << dendl;
+    exit(1);
+  }
+
   ldout(cct, 1) << "finished global_init_daemonize" << dendl;
 }