]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/osd: call pubsetbuf() before open() 68861/head
authorMatan Breizman <mbreizma@redhat.com>
Wed, 20 May 2026 08:22:22 +0000 (11:22 +0300)
committerMatan Breizman <mbreizma@redhat.com>
Wed, 20 May 2026 08:22:22 +0000 (11:22 +0300)
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 <mbreizma@redhat.com>
src/crimson/osd/main.cc

index 6f287c9f1f85eddcd952d6faaef33990ecc27a24..86bbbe1ab98d5ccb56aafc25734e8ba622e9087b 100644 (file)
@@ -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([] {