[systemd-commits] 5 commits - src/journal src/systemctl.c

Lennart Poettering lennart at kemper.freedesktop.org
Tue Jan 3 19:00:29 PST 2012


 src/journal/journalctl.c |   25 ++++++++++++++++---------
 src/journal/journald.c   |   18 ++++++++++++------
 src/journal/sd-journal.c |   47 +++++++++++++++++++++++------------------------
 src/systemctl.c          |    4 +++-
 4 files changed, 54 insertions(+), 40 deletions(-)

New commits:
commit 6f003b43043da7b57c0ebe15b86856c8248fea4a
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jan 4 04:00:14 2012 +0100

    journalctl: fix counting of -n parameter

diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index fc1fed2..0e1fb66 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -148,6 +148,7 @@ int main(int argc, char *argv[]) {
         int r, i, fd;
         sd_journal *j = NULL;
         unsigned line = 0;
+        bool need_seek = false;
 
         log_parse_environment();
         log_open();
@@ -184,16 +185,19 @@ int main(int argc, char *argv[]) {
                 }
 
                 r = sd_journal_previous_skip(j, arg_lines);
-                if (r < 0) {
-                        log_error("Failed to iterate through journal: %s", strerror(-r));
-                        goto finish;
-                }
         } else {
                 r = sd_journal_seek_head(j);
                 if (r < 0) {
                         log_error("Failed to seek to head: %s", strerror(-r));
                         goto finish;
                 }
+
+                r = sd_journal_next(j);
+        }
+
+        if (r < 0) {
+                log_error("Failed to iterate through journal: %s", strerror(-r));
+                goto finish;
         }
 
         if (!arg_no_pager && !arg_follow) {
@@ -210,11 +214,12 @@ int main(int argc, char *argv[]) {
                 struct pollfd pollfd;
 
                 for (;;) {
-                        r = sd_journal_next(j);
-
-                        if (r < 0) {
-                                log_error("Failed to iterate through journal: %s", strerror(-r));
-                                goto finish;
+                        if (need_seek) {
+                                r = sd_journal_next(j);
+                                if (r < 0) {
+                                        log_error("Failed to iterate through journal: %s", strerror(-r));
+                                        goto finish;
+                                }
                         }
 
                         if (r == 0)
@@ -225,6 +230,8 @@ int main(int argc, char *argv[]) {
                         r = output_journal(j, arg_output, line, arg_show_all);
                         if (r < 0)
                                 goto finish;
+
+                        need_seek = true;
                 }
 
                 if (!arg_follow)
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index 78a91a3..05c0d96 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -683,14 +683,23 @@ _public_ int sd_journal_previous(sd_journal *j) {
         return real_journal_next(j, DIRECTION_UP);
 }
 
-_public_ int sd_journal_next_skip(sd_journal *j, uint64_t skip) {
+static int real_journal_next_skip(sd_journal *j, direction_t direction, uint64_t skip) {
         int c = 0, r;
 
         if (!j)
                 return -EINVAL;
 
-        while (skip > 0) {
-                r = sd_journal_next(j);
+        if (skip == 0) {
+                /* If this is not a discrete skip, then at least
+                 * resolve the current location */
+                if (j->current_location.type != LOCATION_DISCRETE)
+                        return real_journal_next(j, direction);
+
+                return 0;
+        }
+
+        do {
+                r = real_journal_next(j, direction);
                 if (r < 0)
                         return r;
 
@@ -699,30 +708,17 @@ _public_ int sd_journal_next_skip(sd_journal *j, uint64_t skip) {
 
                 skip--;
                 c++;
-        }
+        } while (skip > 0);
 
         return c;
 }
 
-_public_ int sd_journal_previous_skip(sd_journal *j, uint64_t skip) {
-        int c = 0, r;
-
-        if (!j)
-                return -EINVAL;
-
-        while (skip > 0) {
-                r = sd_journal_previous(j);
-                if (r < 0)
-                        return r;
-
-                if (r == 0)
-                        return c;
-
-                skip--;
-                c++;
-        }
+_public_ int sd_journal_next_skip(sd_journal *j, uint64_t skip) {
+        return real_journal_next_skip(j, DIRECTION_DOWN, skip);
+}
 
-        return 1;
+_public_ int sd_journal_previous_skip(sd_journal *j, uint64_t skip) {
+        return real_journal_next_skip(j, DIRECTION_UP, skip);
 }
 
 _public_ int sd_journal_get_cursor(sd_journal *j, char **cursor) {
diff --git a/src/systemctl.c b/src/systemctl.c
index 10e3991..6f87b06 100644
--- a/src/systemctl.c
+++ b/src/systemctl.c
@@ -2262,8 +2262,10 @@ static void print_status_info(UnitStatusInfo *i) {
                 }
         }
 
-        if (i->id && arg_transport != TRANSPORT_SSH)
+        if (i->id && arg_transport != TRANSPORT_SSH) {
+                printf("\n");
                 show_journal_by_service(i->id, OUTPUT_SHORT, NULL, 0, 0, 0, arg_all);
+        }
 
         if (i->need_daemon_reload)
                 printf("\n%sWarning:%s Unit file changed on disk, 'systemctl %s daemon-reload' recommended.\n",

commit cf5eb6a110c39b36dd07457180b749f32488bcf5
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jan 4 03:45:50 2012 +0100

    journal: fix reverse traversing of entries

diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index 1833c75..78a91a3 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -488,7 +488,7 @@ static int next_with_matches(sd_journal *j, JournalFile *f, direction_t directio
 
                 /* Make sure we don't match the entry we are starting
                  * from. */
-                found = cp > *offset;
+                found = cp != *offset;
 
                 np = 0;
                 LIST_FOREACH(matches, m, j->matches) {

commit b4e5f9201706cbd0c83645175649119e87c2c91c
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jan 4 03:45:24 2012 +0100

    journal: add missing error check

diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index fde1a0b..1833c75 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -372,6 +372,9 @@ static int find_location(sd_journal *j, JournalFile *f, direction_t direction, O
                         else
                                 r = journal_file_next_entry_for_data(f, NULL, 0, dp, direction, &c, &cp);
 
+                        if (r < 0)
+                                return r;
+
                         if (!term_match) {
                                 term_match = m;
 

commit 9c4e3f2624102c0b59cea78aabe4ed1f1d60064e
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jan 4 03:45:14 2012 +0100

    journal: don't mind too much if we can't find a monotonic timestamp

diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index 555c35e..fde1a0b 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -349,7 +349,7 @@ static int find_location(sd_journal *j, JournalFile *f, direction_t direction, O
 
                         r = journal_file_move_to_entry_by_monotonic(f, j->current_location.boot_id, j->current_location.monotonic, direction, &o, &p);
                         if (r <= 0)
-                                return r;
+                                return r == -ENOENT ? 0 : r;
                 }
 
                 LIST_FOREACH(matches, m, j->matches) {

commit b1a0ab714863ae77e4683820757b3f49c03a0049
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jan 4 02:33:11 2012 +0100

    journald: don't rotate on startup

diff --git a/src/journal/journald.c b/src/journal/journald.c
index b42be8d..47fe6ed 100644
--- a/src/journal/journald.c
+++ b/src/journal/journald.c
@@ -306,14 +306,11 @@ static JournalFile* find_journal(Server *s, uid_t uid) {
         return f;
 }
 
-static void server_vacuum(Server *s) {
-        Iterator i;
+static void server_rotate(Server *s) {
+        JournalFile *f;
         void *k;
-        char *p;
-        char ids[33];
-        sd_id128_t machine;
+        Iterator i;
         int r;
-        JournalFile *f;
 
         log_info("Rotating...");
 
@@ -336,6 +333,13 @@ static void server_vacuum(Server *s) {
                 else
                         hashmap_replace(s->user_journals, k, f);
         }
+}
+
+static void server_vacuum(Server *s) {
+        char *p;
+        char ids[33];
+        sd_id128_t machine;
+        int r;
 
         log_info("Vacuuming...");
 
@@ -565,6 +569,7 @@ retry:
                 if (r == -E2BIG && !vacuumed) {
                         log_info("Allocation limit reached.");
 
+                        server_rotate(s);
                         server_vacuum(s);
                         vacuumed = true;
 
@@ -1308,6 +1313,7 @@ static int server_flush_to_var(Server *s) {
                         log_info("Allocation limit reached.");
 
                         journal_file_post_change(s->system_journal);
+                        server_rotate(s);
                         server_vacuum(s);
 
                         r = journal_file_copy_entry(f, s->system_journal, o, f->current_offset, NULL, NULL, NULL);



More information about the systemd-commits mailing list