From 037951c51fde564f2ee42e36351a97b041535172 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 1 Mar 2018 21:52:33 -0600 Subject: [PATCH] global/global_init: close stdout in postfork_finish, not start 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 (cherry picked from commit 056d02b0649d28200170f729dc0d625209206cfb) --- src/global/global_init.cc | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/global/global_init.cc b/src/global/global_init.cc index 147f294a350ee..7d0abb622a372 100644 --- a/src/global/global_init.cc +++ b/src/global/global_init.cc @@ -414,13 +414,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) @@ -435,8 +428,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)) { @@ -447,6 +440,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; } -- 2.39.5