From: Matan Breizman Date: Wed, 20 May 2026 08:22:22 +0000 (+0300) Subject: crimson/osd: call pubsetbuf() before open() X-Git-Tag: v21.0.1~159^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8297ead0e24df268efd25535d81533ee2ba8f73a;p=ceph.git crimson/osd: call pubsetbuf() before open() Move rdbuf()->pubsetbuf(nullptr, 0) before ofstream::open() since libstdc++ may ignore setbuf() once the filebuf is associated with a file. ``` setbuf() may only be called when the std::basic_filebuf is not associated with a file (has no effect otherwise) ``` https://en.cppreference.com/cpp/io/basic_filebuf/setbuf Signed-off-by: Matan Breizman --- diff --git a/src/crimson/osd/main.cc b/src/crimson/osd/main.cc index 6f287c9f1f8..86bbbe1ab98 100644 --- a/src/crimson/osd/main.cc +++ b/src/crimson/osd/main.cc @@ -159,17 +159,17 @@ int main(int argc, const char* argv[]) DEBUG("initializing logger output"); std::ofstream log_file_stream; if (auto log_file = local_conf()->log_file; !log_file.empty()) { + // seastar::logger::do_log() writes to _out from every shard's thread + // with no lock. std::cerr is safe because it is unbuffered; a buffered + // ofstream is not. Disable buffering so each write() is a single syscall, + // matching cerr's thread-safety guarantee. + log_file_stream.rdbuf()->pubsetbuf(nullptr, 0); log_file_stream.open(log_file, std::ios::app | std::ios::out); try { seastar::throw_system_error_on(log_file_stream.fail()); } catch (const std::system_error& e) { ceph_abort_msg(fmt::format("unable to open log file: {}", e.what())); } - // seastar::logger::do_log() writes to _out from every shard's thread - // with no lock. std::cerr is safe because it is unbuffered; a buffered - // ofstream is not. Disable buffering so each write() is a single syscall, - // matching cerr's thread-safety guarantee. - log_file_stream.rdbuf()->pubsetbuf(nullptr, 0); logger().set_ostream(log_file_stream); } auto reset_logger = seastar::defer([] {