Commit 09fac26c authored by Vladimír Čunát's avatar Vladimír Čunát

treewide: fix flushing of messages to logs in some cases

... by setting FILE* properties and replace the explicit flushes.
Explicit flushing couldn't be well done e.g. for lua's error() function.
In particular, we had problems with journald not getting logs timely.
parent 71e87558
......@@ -14,6 +14,7 @@ Bugfixes
- policy module: support '#' for separating port numbers, for consistency
- fix startup on macOS+BSD when </dev/null and cqueues installed
- policy.RPZ: log problems from zone-file level of parser as well (#453)
- fix flushing of messages to logs in some cases (!781)
Improvements
------------
......
......@@ -173,7 +173,6 @@ static void tty_process_input(uv_stream_t *stream, ssize_t nread, const uv_buf_t
lua_settop(L, 0);
}
finish:
fflush(out);
free(cmd);
/* Close if redirected */
if (stream_fd != STDIN_FILENO) {
......@@ -420,6 +419,12 @@ static int run_worker(uv_loop_t *loop, struct engine *engine, fd_array_t *ipc_se
return 1;
}
if (setvbuf(stdout, NULL, _IONBF, 0) || setvbuf(stderr, NULL, _IONBF, 0)) {
kr_log_error("[system] failed to to set output buffering (ignored): %s\n",
strerror(errno));
fflush(stderr);
}
/* Control sockets or TTY */
auto_free char *sock_file = NULL;
uv_pipe_t pipe;
......@@ -428,7 +433,6 @@ static int run_worker(uv_loop_t *loop, struct engine *engine, fd_array_t *ipc_se
if (args->interactive) {
if (!args->quiet)
printf("[system] interactive mode\n> ");
fflush(stdout);
uv_pipe_open(&pipe, 0);
uv_read_start((uv_stream_t*) &pipe, tty_alloc, tty_process_input);
} else {
......
......@@ -118,12 +118,11 @@ bool kr_verbose_set(bool status)
void kr_log_verbose(const char *fmt, ...)
{
if (kr_verbose_status) {
if (unlikely(kr_verbose_status)) {
va_list args;
va_start(args, fmt);
vprintf(fmt, args);
va_end(args);
fflush(stdout);
}
}
......@@ -141,7 +140,6 @@ void kr_log_qverbose_impl(const struct kr_query *qry, const char *cls, const cha
va_start(args, fmt);
vprintf(fmt, args);
va_end(args);
fflush(stdout);
}
bool kr_log_trace(const struct kr_query *query, const char *source, const char *fmt, ...)
......
......@@ -46,7 +46,7 @@ typedef void (*trace_callback_f)(struct kr_request *request);
/** @brief Callback for request logging handler. */
typedef void (*trace_log_f)(const struct kr_query *query, const char *source, const char *msg);
#define kr_log_info(...) do { printf(__VA_ARGS__); fflush(stdout); } while(0)
#define kr_log_info printf
#define kr_log_error(...) fprintf(stderr, ## __VA_ARGS__)
/* Always export these, but override direct calls by macros conditionally. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment