[systemd-commits] 4 commits - TODO src/journal

Lennart Poettering lennart at kemper.freedesktop.org
Wed May 30 13:52:35 PDT 2012


 TODO                     |    2 +-
 src/journal/journalctl.c |   40 +++++++++++++++++++++++++++++++++++++++-
 src/journal/sd-journal.c |   11 ++++++++++-
 3 files changed, 50 insertions(+), 3 deletions(-)

New commits:
commit d94117a93c0a8431de5c765f21a97f6eb32580da
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed May 30 22:46:07 2012 +0200

    journal: don't allow adding invalid matches to the context

diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index 09ce949..9f46f5c 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -115,7 +115,11 @@ _public_ int sd_journal_add_match(sd_journal *j, const void *data, size_t size)
                 return -EINVAL;
         if (!data)
                 return -EINVAL;
-        if (size <= 0)
+        if (size <= 1)
+                return -EINVAL;
+        if (!memchr(data, '=', size))
+                return -EINVAL;
+        if (*(char*) data == '=')
                 return -EINVAL;
 
         /* FIXME: iterating with multiple matches is currently

commit e51240886f54e0128b1711c7dd0454b23e3f7d5e
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed May 30 22:45:47 2012 +0200

    journalctl: check first if match is a path name

diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index daf4281..9d44032 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -35,12 +35,11 @@
 
 #include "log.h"
 #include "util.h"
+#include "path-util.h"
 #include "build.h"
 #include "pager.h"
 #include "logs-show.h"
 
-#define SD_JOURNALCTL_EXE "_EXE="
-
 static OutputMode arg_output = OUTPUT_SHORT;
 static bool arg_follow = false;
 static bool arg_show_all = false;
@@ -209,7 +208,6 @@ int main(int argc, char *argv[]) {
         unsigned line = 0;
         bool need_seek = false;
         struct stat st;
-        char* journal_exe_buff;
 
         log_parse_environment();
         log_open();
@@ -235,25 +233,42 @@ int main(int argc, char *argv[]) {
         }
 
         for (i = optind; i < argc; i++) {
-                if (strchr(argv[i], '=')) {
-                        r = sd_journal_add_match(j, argv[i], strlen(argv[i]));
-                } else {
-                        if (stat(argv[i], &st) < 0) {
-                                log_error("Failed to add match: %s", strerror(-r));
-                                goto finish; /* maybe try sd_journal_add_match() when stat() fails,
-                                              * even thought we know there is no '=' ? */
-                        } else if (S_ISREG(st.st_mode) &&
-                                   S_IXUSR & st.st_mode) {
-                                journal_exe_buff = malloc(strlen(SD_JOURNALCTL_EXE) + strlen(argv[i]) + 1);
-                                journal_exe_buff = strcpy(journal_exe_buff, SD_JOURNALCTL_EXE);
-                                strncat(journal_exe_buff, argv[i], strlen(argv[i]));
-                                r = sd_journal_add_match(j, journal_exe_buff, strlen(journal_exe_buff));
-                                free(journal_exe_buff);
+                if (path_is_absolute(argv[i])) {
+                        char *p = NULL;
+                        const char *path;
+
+                        p = canonicalize_file_name(argv[i]);
+                        path = p ? p : argv[i];
+
+                        if (stat(path, &st) < 0)  {
+                                free(p);
+                                log_error("Couldn't stat file: %m");
+                                r = -errno;
+                                goto finish;
+                        }
+
+                        if (S_ISREG(st.st_mode) && (0111 & st.st_mode)) {
+                                char *t;
+
+                                t = strappend("_EXE=", path);
+                                if (!t) {
+                                        free(p);
+                                        log_error("Out of memory");
+                                        goto finish;
+                                }
+
+                                r = sd_journal_add_match(j, t, strlen(t));
+                                free(t);
                         } else {
+                                free(p);
                                 log_error("File is not a regular file or is not executable: %s", argv[i]);
                                 goto finish;
                         }
-                }
+
+                        free(p);
+                } else
+                        r = sd_journal_add_match(j, argv[i], strlen(argv[i]));
+
                 if (r < 0) {
                         log_error("Failed to add match: %s", strerror(-r));
                         goto finish;

commit 509407003de0c77259e5e46b567d2a464acbb6f4
Author: Shawn Landden <shawnlandden at gmail.com>
Date:   Wed May 30 09:43:23 2012 -0700

    journalctl: support /usr/bin/nginx, etc

diff --git a/TODO b/TODO
index 15d596a..90bd48c 100644
--- a/TODO
+++ b/TODO
@@ -32,7 +32,7 @@ Features:
 
 * parse kernel cmdline option for capability bset
 
-* journalctl /dev/sda, journalctl /usr/bin/httpd, journalctl --device=b12:8 (--device=n12, --device=+usb:1-1)
+* journalctl /dev/sda, journalctl --device=b12:8 (--device=n12, --device=+usb:1-1)
 
 * make use of /sys/power/wake_lock in inhibitors
 
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 58778a8..daf4281 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -29,6 +29,7 @@
 #include <sys/poll.h>
 #include <time.h>
 #include <getopt.h>
+#include <sys/stat.h>
 
 #include <systemd/sd-journal.h>
 
@@ -38,6 +39,8 @@
 #include "pager.h"
 #include "logs-show.h"
 
+#define SD_JOURNALCTL_EXE "_EXE="
+
 static OutputMode arg_output = OUTPUT_SHORT;
 static bool arg_follow = false;
 static bool arg_show_all = false;
@@ -205,6 +208,8 @@ int main(int argc, char *argv[]) {
         sd_journal *j = NULL;
         unsigned line = 0;
         bool need_seek = false;
+        struct stat st;
+        char* journal_exe_buff;
 
         log_parse_environment();
         log_open();
@@ -230,7 +235,25 @@ int main(int argc, char *argv[]) {
         }
 
         for (i = optind; i < argc; i++) {
-                r = sd_journal_add_match(j, argv[i], strlen(argv[i]));
+                if (strchr(argv[i], '=')) {
+                        r = sd_journal_add_match(j, argv[i], strlen(argv[i]));
+                } else {
+                        if (stat(argv[i], &st) < 0) {
+                                log_error("Failed to add match: %s", strerror(-r));
+                                goto finish; /* maybe try sd_journal_add_match() when stat() fails,
+                                              * even thought we know there is no '=' ? */
+                        } else if (S_ISREG(st.st_mode) &&
+                                   S_IXUSR & st.st_mode) {
+                                journal_exe_buff = malloc(strlen(SD_JOURNALCTL_EXE) + strlen(argv[i]) + 1);
+                                journal_exe_buff = strcpy(journal_exe_buff, SD_JOURNALCTL_EXE);
+                                strncat(journal_exe_buff, argv[i], strlen(argv[i]));
+                                r = sd_journal_add_match(j, journal_exe_buff, strlen(journal_exe_buff));
+                                free(journal_exe_buff);
+                        } else {
+                                log_error("File is not a regular file or is not executable: %s", argv[i]);
+                                goto finish;
+                        }
+                }
                 if (r < 0) {
                         log_error("Failed to add match: %s", strerror(-r));
                         goto finish;

commit ab4979d202e12d60bb2e31dee32fd3e79a4453fd
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed May 30 22:30:35 2012 +0200

    journalctl: for now complain if more than one match is provided since this is still broken

diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index 4f3f1b5..09ce949 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -118,6 +118,11 @@ _public_ int sd_journal_add_match(sd_journal *j, const void *data, size_t size)
         if (size <= 0)
                 return -EINVAL;
 
+        /* FIXME: iterating with multiple matches is currently
+         * broken */
+        if (j->matches)
+                return -ENOTSUP;
+
         le_hash = htole64(hash64(data, size));
 
         LIST_FOREACH(matches, m, j->matches) {



More information about the systemd-commits mailing list