From: Vito Caputo Date: Fri, 7 Jul 2017 18:32:21 +0000 (-0700) Subject: shared: leave output_journal() output in buffer (#6304) X-Git-Tag: v234~26 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b1aa5ced45951ed470188b362c61827fb31da2ab;p=thirdparty%2Fsystemd.git shared: leave output_journal() output in buffer (#6304) e268b81e moved an fflush() from output_json() to the generic output_journal(), when it probably should have deleted all fflush() calls from logs-show.c altogether. The caller supplies the FILE * to these functions, and should be in charge of flushing as needed. The current implementation essentially defeats any buffering stdio was bringing to the table, resulting in extraneous tiny write() calls in commands like `journalctl -b`. This commit removes the fflush() call from output_journal(), and adds them to journalctl before waiting for more entries and at completion. This way in the hot path when journalctl loops on entries stdio can combine multiple entries into bulkier write() calls. --- diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 698a5a9dc85..2313c8c6786 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -2483,6 +2483,7 @@ int main(int argc, char *argv[]) { break; } + fflush(stdout); r = sd_journal_wait(j, (uint64_t) -1); if (r < 0) { log_error_errno(r, "Couldn't wait for journal event: %m"); @@ -2493,6 +2494,7 @@ int main(int argc, char *argv[]) { } finish: + fflush(stdout); pager_close(); strv_free(arg_file); diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index c735fa159d9..02ae4265c6b 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -991,7 +991,6 @@ int output_journal( n_columns = columns(); ret = output_funcs[mode](f, j, mode, n_columns, flags); - fflush(stdout); if (ellipsized && ret > 0) *ellipsized = true;