X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjournal%2Fjournalctl.c;h=9a2d2553617ad9b50570f50ce4020e0da8a445db;hb=13b84ec7df103ce388910a2b868fe1668c1e27ef;hp=2f043a48d544f25af757e87e511c0d6caeccec52;hpb=a54e3b3d6a4fe28a39729f4c5ad11cd26706110c;p=elogind.git diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 2f043a48d..9a2d25536 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -45,6 +45,7 @@ #include "logs-show.h" #include "util.h" #include "path-util.h" +#include "fileio.h" #include "build.h" #include "pager.h" #include "logs-show.h" @@ -133,8 +134,9 @@ static int help(void) { " -n --lines[=INTEGER] Number of journal entries to show\n" " --no-tail Show all lines, even in follow mode\n" " -r --reverse Show the newest entries first\n" - " -o --output=STRING Change journal output mode (short, short-monotonic,\n" - " verbose, export, json, json-pretty, json-sse, cat)\n" + " -o --output=STRING Change journal output mode (short, short-iso,\n" + " short-precise, short-monotonic, verbose,\n" + " export, json, json-pretty, json-sse, cat)\n" " -x --catalog Add message explanations where available\n" " -l --full Do not ellipsize fields\n" " -a --all Show all fields, including long and unprintable\n" @@ -627,8 +629,9 @@ static int add_matches(sd_journal *j, char **args) { if (streq(*i, "+")) r = sd_journal_add_disjunction(j); else if (path_is_absolute(*i)) { - _cleanup_free_ char *p, *t = NULL; + _cleanup_free_ char *p, *t = NULL, *t2 = NULL; const char *path; + _cleanup_free_ char *interpreter = NULL; struct stat st; p = canonicalize_file_name(*i); @@ -639,9 +642,27 @@ static int add_matches(sd_journal *j, char **args) { return -errno; } - if (S_ISREG(st.st_mode) && (0111 & st.st_mode)) - t = strappend("_EXE=", path); - else if (S_ISCHR(st.st_mode)) + if (S_ISREG(st.st_mode) && (0111 & st.st_mode)) { + if (executable_is_script(path, &interpreter) > 0) { + _cleanup_free_ char *comm; + + comm = strndup(path_get_file_name(path), 15); + if (!comm) + return log_oom(); + + t = strappend("_COMM=", comm); + + /* Append _EXE only if the interpreter is not a link. + Otherwise it might be outdated often. */ + if (lstat(interpreter, &st) == 0 && + !S_ISLNK(st.st_mode)) { + t2 = strappend("_EXE=", interpreter); + if (!t2) + return log_oom(); + } + } else + t = strappend("_EXE=", path); + } else if (S_ISCHR(st.st_mode)) asprintf(&t, "_KERNEL_DEVICE=c%u:%u", major(st.st_rdev), minor(st.st_rdev)); else if (S_ISBLK(st.st_mode)) asprintf(&t, "_KERNEL_DEVICE=b%u:%u", major(st.st_rdev), minor(st.st_rdev)); @@ -654,6 +675,8 @@ static int add_matches(sd_journal *j, char **args) { return log_oom(); r = sd_journal_add_match(j, t, 0); + if (t2) + r = sd_journal_add_match(j, t2, 0); } else r = sd_journal_add_match(j, *i, 0); @@ -1278,11 +1301,12 @@ static int access_check(sd_journal *j) { int main(int argc, char *argv[]) { int r; - _cleanup_journal_close_ sd_journal*j = NULL; + _cleanup_journal_close_ sd_journal *j = NULL; bool need_seek = false; sd_id128_t previous_boot_id; bool previous_boot_id_valid = false, first_line = true; int n_shown = 0; + bool ellipsized = false; setlocale(LC_ALL, ""); log_parse_environment(); @@ -1583,14 +1607,13 @@ int main(int argc, char *argv[]) { if (!arg_merge) { sd_id128_t boot_id; - const char *color_on = on_tty() ? ANSI_HIGHLIGHT_ON : "", - *color_off = on_tty() ? ANSI_HIGHLIGHT_OFF : ""; r = sd_journal_get_monotonic_usec(j, NULL, &boot_id); if (r >= 0) { if (previous_boot_id_valid && !sd_id128_equal(boot_id, previous_boot_id)) - printf("%s-- Reboot --%s\n", color_on, color_off); + printf("%s-- Reboot --%s\n", + ansi_highlight(), ansi_highlight_off()); previous_boot_id = boot_id; previous_boot_id_valid = true; @@ -1603,7 +1626,7 @@ int main(int argc, char *argv[]) { on_tty() * OUTPUT_COLOR | arg_catalog * OUTPUT_CATALOG; - r = output_journal(stdout, j, arg_output, 0, flags); + r = output_journal(stdout, j, arg_output, 0, flags, &ellipsized); need_seek = true; if (r == -EADDRNOTAVAIL) break;