Skip to content

Commit

Permalink
Explicitly set line buffered mode
Browse files Browse the repository at this point in the history
When the output is not a TTY (e.g. when redirected), glibc switches from
line buffering to block buffering for stdout/stderr. Rootcanal's startup
log messages aren't enough to fill a block, so it would appear to just
not log anything at all. Now, `./rootcanal | cat` behaves as expected:
log messages show up immediately.
  • Loading branch information
marshallpierce committed Mar 19, 2024
1 parent d060538 commit 6631c45
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions desktop/root_canal_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <fstream>
#include <future>
#include <optional>
#include <cstdio>

#include "model/setup/async_manager.h"
#include "net/posix/posix_async_socket_connector.h"
Expand Down Expand Up @@ -54,6 +55,10 @@ DEFINE_uint32(link_port, 6403, "link server tcp port");
DEFINE_uint32(link_ble_port, 6404, "le link server tcp port");

int main(int argc, char** argv) {
// always use line buffer mode so log messages are available when redirected
setvbuf(stdout, NULL, _IOLBF, 0);
setvbuf(stderr, NULL, _IOLBF, 0);

gflags::ParseCommandLineFlags(&argc, &argv, true);
rootcanal::log::SetLogColorEnable(FLAGS_enable_log_color);

Expand Down

0 comments on commit 6631c45

Please sign in to comment.