shared/logs-show: urlify CONFIG_FILE in verbose mode
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 1 Jul 2019 18:20:23 +0000 (20:20 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 10 Jul 2019 12:20:09 +0000 (14:20 +0200)
Now all short-*, verbose, with-unit modes are handled. cat, export, json-* are
not, but those are usually used for post-processing, so I don't think it'd be
useful there.

TODO
src/shared/logs-show.c

diff --git a/TODO b/TODO
index a575f9a..4e787a7 100644 (file)
--- a/TODO
+++ b/TODO
@@ -134,9 +134,6 @@ Features:
   sufficient to build a link by prefixing "http://" and suffixing the
   CODE_FILE.
 
-* when outputting log data with journalctl and the log data includes references
-  to configuration files (CONFIG_FILE=), create a clickable link for it.
-
 * Augment MESSAGE_ID with MESSAGE_BASE, in a similar fashion so that we can
   make clickable links from log messages carrying a MESSAGE_ID, that lead to
   some explanatory text online.
index 3864a72..21b3251 100644 (file)
@@ -587,9 +587,11 @@ static int output_verbose(
                 cursor);
 
         JOURNAL_FOREACH_DATA_RETVAL(j, data, length, r) {
-                const char *c;
+                const char *c, *p;
                 int fieldlen;
                 const char *on = "", *off = "";
+                _cleanup_free_ char *urlified = NULL;
+                size_t valuelen;
 
                 c = memchr(data, '=', length);
                 if (!c)
@@ -600,20 +602,28 @@ static int output_verbose(
                 r = field_set_test(output_fields, data, fieldlen);
                 if (r < 0)
                         return r;
-                if (!r)
+                if (r == 0)
                         continue;
 
-                if (flags & OUTPUT_COLOR && startswith(data, "MESSAGE=")) {
+                valuelen = length - 1 - fieldlen;
+
+                if ((flags & OUTPUT_COLOR) && (p = startswith(data, "MESSAGE="))) {
                         on = ANSI_HIGHLIGHT;
                         off = ANSI_NORMAL;
-                }
+                } else if ((p = startswith(data, "CONFIG_FILE="))) {
+                        if (terminal_urlify_path(p, NULL, &urlified) >= 0) {
+                                p = urlified;
+                                valuelen = strlen(urlified);
+                        }
+                } else
+                        p = c + 1;
 
                 if ((flags & OUTPUT_SHOW_ALL) ||
                     (((length < PRINT_CHAR_THRESHOLD) || flags & OUTPUT_FULL_WIDTH)
                      && utf8_is_printable(data, length))) {
                         fprintf(f, "    %s%.*s=", on, fieldlen, (const char*)data);
                         print_multiline(f, 4 + fieldlen + 1, 0, OUTPUT_FULL_WIDTH, 0, false,
-                                        c + 1, length - fieldlen - 1,
+                                        p, valuelen,
                                         NULL);
                         fputs(off, f);
                 } else {