From 056d02b0649d28200170f729dc0d625209206cfb 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 --- 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 08e6d1035de..9855f370882 100644 --- a/src/global/global_init.cc +++ b/src/global/global_init.cc @@ -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; } -- 2.47.3