chiark / gitweb /
journalctl: flip to --full by default
[elogind.git] / src / journal / journalctl.c
index 9a40d69a754ae8e3a7a3a5b09a671c10aaf99277..2f8be1b83e9d37b7382551571760583c4d0f50c8 100644 (file)
@@ -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"
@@ -63,7 +64,7 @@
 static OutputMode arg_output = OUTPUT_SHORT;
 static bool arg_pager_end = false;
 static bool arg_follow = false;
-static bool arg_full = false;
+static bool arg_full = true;
 static bool arg_all = false;
 static bool arg_no_pager = false;
 static int arg_lines = -1;
@@ -133,10 +134,11 @@ 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"
+               "     --no-full             Ellipsize fields\n"
                "  -a --all                 Show all fields, including long and unprintable\n"
                "  -q --quiet               Don't show privilege warning\n"
                "     --no-pager            Do not pipe output into a pager\n"
@@ -173,6 +175,7 @@ static int parse_argv(int argc, char *argv[]) {
         enum {
                 ARG_VERSION = 0x100,
                 ARG_NO_PAGER,
+                ARG_NO_FULL,
                 ARG_NO_TAIL,
                 ARG_NEW_ID128,
                 ARG_USER,
@@ -206,6 +209,7 @@ static int parse_argv(int argc, char *argv[]) {
                 { "output",         required_argument, NULL, 'o'                },
                 { "all",            no_argument,       NULL, 'a'                },
                 { "full",           no_argument,       NULL, 'l'                },
+                { "no-full",        no_argument,       NULL, ARG_NO_FULL        },
                 { "lines",          optional_argument, NULL, 'n'                },
                 { "no-tail",        no_argument,       NULL, ARG_NO_TAIL        },
                 { "new-id128",      no_argument,       NULL, ARG_NEW_ID128      },
@@ -296,6 +300,10 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_full = true;
                         break;
 
+                case ARG_NO_FULL:
+                        arg_full = false;
+                        break;
+
                 case 'a':
                         arg_all = true;
                         break;
@@ -627,8 +635,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 +648,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 +681,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);
 
@@ -744,7 +773,7 @@ static int get_relative_boot_id(sd_journal *j, sd_id128_t *boot_id, int relative
 
                 if (!id ||
                     relative <= 0 ? (id - all_ids) + relative < 0 :
-                                    (id - all_ids) + relative >= count)
+                                    (id - all_ids) + relative >= (int) count)
                         return -EADDRNOTAVAIL;
 
                 *boot_id = (id + relative)->id;
@@ -781,7 +810,7 @@ static int add_boot(sd_journal *j) {
 
                 offset = arg_boot_descriptor + 32;
 
-                if (*offset != '-' && *offset != '+') {
+                if (*offset && *offset != '-' && *offset != '+') {
                         log_error("Relative boot ID offset must start with a '+' or a '-', found '%s' ", offset);
                         return -EINVAL;
                 }
@@ -1278,11 +1307,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 +1613,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;
@@ -1599,11 +1628,11 @@ int main(int argc, char *argv[]) {
 
                         flags =
                                 arg_all * OUTPUT_SHOW_ALL |
-                                (arg_full || !on_tty() || pager_have()) * OUTPUT_FULL_WIDTH |
+                                arg_full * OUTPUT_FULL_WIDTH |
                                 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;