X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjournal%2Fjournalctl.c;h=abcfabe75d4e56d02b7f2d1b1a72c85081195638;hb=0d7e32fa0a8e5f21a66c2f5504adabfa40523efc;hp=0d37107874f262f41b128e48a04e689a4fb8d431;hpb=dca6219e04505e9fa10b32e71059ce2abfae1dad;p=elogind.git diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 0d3710787..abcfabe75 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -198,6 +198,21 @@ static int parse_argv(int argc, char *argv[]) { return 1; } +static bool on_tty(void) { + static int t = -1; + + /* Note that this is invoked relatively early, before we start + * the pager. That means the value we return reflects whether + * we originally were started on a tty, not if we currently + * are. But this is intended, since we want colour and so on + * when run in our own pager. */ + + if (_unlikely_(t < 0)) + t = isatty(STDOUT_FILENO) > 0; + + return t; +} + static int generate_new_id128(void) { sd_id128_t id; int r; @@ -256,8 +271,7 @@ static int add_matches(sd_journal *j, char **args) { t = strappend("_EXE=", path); if (!t) { free(p); - log_error("Out of memory"); - return -ENOMEM; + return log_oom(); } r = sd_journal_add_match(j, t, 0); @@ -312,6 +326,7 @@ int main(int argc, char *argv[]) { bool need_seek = false; sd_id128_t previous_boot_id; bool previous_boot_id_valid = false; + bool have_pager; log_parse_environment(); log_open(); @@ -397,10 +412,8 @@ int main(int argc, char *argv[]) { goto finish; } - if (!arg_no_pager && !arg_follow) { - columns(); - pager_open(); - } + on_tty(); + have_pager = !arg_no_pager && !arg_follow && pager_open(); if (arg_output == OUTPUT_JSON) { fputc('[', stdout); @@ -410,6 +423,10 @@ int main(int argc, char *argv[]) { for (;;) { for (;;) { sd_id128_t boot_id; + int flags = + arg_show_all * OUTPUT_SHOW_ALL | + have_pager * OUTPUT_FULL_WIDTH | + on_tty() * OUTPUT_COLOR; if (need_seek) { r = sd_journal_next(j); @@ -434,7 +451,7 @@ int main(int argc, char *argv[]) { line ++; - r = output_journal(j, arg_output, line, 0, arg_show_all); + r = output_journal(j, arg_output, line, 0, flags); if (r < 0) goto finish;