[systemd-commits] man/journalctl.xml src/journal

Lennart Poettering lennart at kemper.freedesktop.org
Thu Aug 9 08:06:25 PDT 2012


 man/journalctl.xml       |   17 +++++++++++++++++
 src/journal/journalctl.c |   27 ++++++++++++++-------------
 2 files changed, 31 insertions(+), 13 deletions(-)

New commits:
commit b6a345143bf6ffdc87a7149015f75c03be440b10
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Aug 9 17:05:29 2012 +0200

    journalctl: support device node matches as shortcut

diff --git a/man/journalctl.xml b/man/journalctl.xml
index cd17ca6..3cfda5b 100644
--- a/man/journalctl.xml
+++ b/man/journalctl.xml
@@ -86,6 +86,15 @@
                 command line all matches before and after are combined
                 in a disjunction (i.e. logical OR).</para>
 
+                <para>As shortcuts for a few types of field/value
+                matches file paths may be specified. If a file path
+                refers to an executable file, this is equivalent to an
+                <literal>_EXE=</literal> match for the canonicalized
+                binary path. Similar, if a path refers to a device
+                node, this is equivalent to a
+                <literal>_KERNEL_DEVICE=</literal> match for the
+                device.</para>
+
                 <para>Output is interleaved from all accessible
                 journal files, whether they are rotated or currently
                 being written, and regardless whether they belong to the
@@ -357,6 +366,14 @@
 
                 <programlisting>journalctl _SYSTEMD_UNIT=avahi-daemon.service _PID=28097 + _SYSTEMD_UNIT=dbus.service</programlisting>
 
+                <para>Show all logs generated by the D-Bus executable:</para>
+
+                <programlisting>journalctl /usr/bin/dbus-daemon</programlisting>
+
+                <para>Show all logs of the kernel device node <filename>/dev/sda</filename>:</para>
+
+                <programlisting>journalctl /dev/sda</programlisting>
+
         </refsect1>
 
         <refsect1>
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 1095942..62bb904 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -305,7 +305,7 @@ static int add_matches(sd_journal *j, char **args) {
                 if (streq(*i, "+"))
                         r = sd_journal_add_disjunction(j);
                 else if (path_is_absolute(*i)) {
-                        char *p;
+                        char *p, *t = NULL;
                         const char *path;
                         struct stat st;
 
@@ -318,24 +318,25 @@ static int add_matches(sd_journal *j, char **args) {
                                 return -errno;
                         }
 
-                        if (S_ISREG(st.st_mode) && (0111 & st.st_mode)) {
-                                char *t;
-
+                        if (S_ISREG(st.st_mode) && (0111 & st.st_mode))
                                 t = strappend("_EXE=", path);
-                                if (!t) {
-                                        free(p);
-                                        return log_oom();
-                                }
-
-                                r = sd_journal_add_match(j, t, 0);
-                                free(t);
-                        } else {
+                        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));
+                        else {
                                 free(p);
-                                log_error("File is not a regular file or is not executable: %s", *i);
+                                log_error("File is not a device node, regular file or is not executable: %s", *i);
                                 return -EINVAL;
                         }
 
                         free(p);
+
+                        if (!t)
+                                return log_oom();
+
+                        r = sd_journal_add_match(j, t, 0);
+                        free(t);
                 } else
                         r = sd_journal_add_match(j, *i, 0);
 



More information about the systemd-commits mailing list