[systemd-commits] 6 commits - src/journal src/sd-id128.h src/test-id128.c

Lennart Poettering lennart at kemper.freedesktop.org
Tue Jan 3 17:21:43 PST 2012


 src/journal/journal-file.c |   21 ++++++++++++++++-----
 src/journal/journalctl.c   |   38 +++++++++++++++++++++++++++++++-------
 src/journal/sd-journal.c   |    3 +++
 src/sd-id128.h             |    6 +++---
 src/test-id128.c           |    2 +-
 5 files changed, 54 insertions(+), 16 deletions(-)

New commits:
commit a99c349d0d54ca4946c6f81670ab9890f2b4f497
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jan 4 02:21:04 2012 +0100

    journal: when increasing window, make sure to use the increased window

diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index 977cfa1..95a5aaf 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -332,11 +332,11 @@ static int journal_file_move_to(JournalFile *f, int wt, uint64_t offset, uint64_
 
                 delta = PAGE_ALIGN((DEFAULT_WINDOW_SIZE - size) / 2);
 
-                if (offset < delta)
+                if (delta > offset)
                         delta = offset;
 
                 offset -= delta;
-                size += (DEFAULT_WINDOW_SIZE - delta);
+                size = DEFAULT_WINDOW_SIZE;
         } else
                 delta = 0;
 

commit 4bbdcdb301f8ef6f8b9e943210ab61250003c517
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jan 4 02:16:38 2012 +0100

    journal: apply seek check before resizing window, and refresh stat data if necessary

diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index 15a752d..977cfa1 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -296,6 +296,15 @@ static int journal_file_move_to(JournalFile *f, int wt, uint64_t offset, uint64_
         assert(wt >= 0);
         assert(wt < _WINDOW_MAX);
 
+        if (offset + size > (uint64_t) f->last_stat.st_size) {
+                /* Hmm, out of range? Let's refresh the fstat() data
+                 * first, before we trust that check. */
+
+                if (fstat(f->fd, &f->last_stat) < 0 ||
+                    offset + size > (uint64_t) f->last_stat.st_size)
+                        return -EADDRNOTAVAIL;
+        }
+
         w = f->windows + wt;
 
         if (_likely_(w->ptr &&
@@ -331,9 +340,6 @@ static int journal_file_move_to(JournalFile *f, int wt, uint64_t offset, uint64_
         } else
                 delta = 0;
 
-        if (offset > (uint64_t) f->last_stat.st_size)
-                return -EADDRNOTAVAIL;
-
         if (offset + size > (uint64_t) f->last_stat.st_size)
                 size = PAGE_ALIGN((uint64_t) f->last_stat.st_size - offset);
 

commit b788cc23aa50682fe80c1b78cc5e42aaf7d76bc5
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jan 4 02:15:45 2012 +0100

    journal: add memory barrier before linking in newly created entries

diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index 45aab0e..15a752d 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -138,6 +138,9 @@ static int journal_file_refresh_header(JournalFile *f) {
         f->header->boot_id = boot_id;
 
         f->header->state = STATE_ONLINE;
+
+        __sync_synchronize();
+
         return 0;
 }
 
@@ -898,6 +901,8 @@ static int journal_file_link_entry(JournalFile *f, Object *o, uint64_t offset) {
         assert(offset > 0);
         assert(o->object.type == OBJECT_ENTRY);
 
+        __sync_synchronize();
+
         /* Link up the entry itself */
         r = link_entry_into_array(f,
                                   &f->header->entry_array_offset,

commit 4b067dc9d2b8836a2250315445686ae83993a9b7
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jan 4 02:15:08 2012 +0100

    journal: add missing error check

diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index bb3b0ae..555c35e 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -524,6 +524,9 @@ static int next_with_matches(sd_journal *j, JournalFile *f, direction_t directio
                          * matches are not OK */
 
                         r = journal_file_next_entry_for_data(f, c, cp, le64toh(c->entry.items[k].object_offset), direction, &qo, &q);
+                        if (r < 0)
+                                return r;
+
                         if (r > 0) {
 
                                 if (direction == DIRECTION_DOWN) {

commit 2100675e9fe0707fae8cee13fbe9316e94ef98f9
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jan 4 02:14:42 2012 +0100

    journalctl: add -n switch

diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 4c20ff6..fc1fed2 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -42,7 +42,7 @@ static output_mode arg_output = OUTPUT_SHORT;
 static bool arg_follow = false;
 static bool arg_show_all = false;
 static bool arg_no_pager = false;
-
+static int arg_lines = -1;
 
 static int help(void) {
 
@@ -53,6 +53,7 @@ static int help(void) {
                "     --no-pager       Do not pipe output into a pager\n"
                "  -a --all            Show all properties, including long and unprintable\n"
                "  -f --follow         Follow journal\n"
+               "  -n --lines=INTEGER  Lines to show\n"
                "  -o --output=STRING  Change output mode (short, verbose, export, json)\n",
                program_invocation_short_name);
 
@@ -73,15 +74,16 @@ static int parse_argv(int argc, char *argv[]) {
                 { "follow",    no_argument,       NULL, 'f'           },
                 { "output",    required_argument, NULL, 'o'           },
                 { "all",       no_argument,       NULL, 'a'           },
+                { "lines",     required_argument, NULL, 'n'           },
                 { NULL,        0,                 NULL, 0             }
         };
 
-        int c;
+        int c, r;
 
         assert(argc >= 0);
         assert(argv);
 
-        while ((c = getopt_long(argc, argv, "hfo:a", options, NULL)) >= 0) {
+        while ((c = getopt_long(argc, argv, "hfo:an:", options, NULL)) >= 0) {
 
                 switch (c) {
 
@@ -122,6 +124,14 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_show_all = true;
                         break;
 
+                case 'n':
+                        r = safe_atoi(optarg, &arg_lines);
+                        if (r < 0) {
+                                log_error("Failed to parse lines '%s'", optarg);
+                                return -EINVAL;
+                        }
+                        break;
+
                 case '?':
                         return -EINVAL;
 
@@ -166,10 +176,24 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
-        r = sd_journal_seek_head(j);
-        if (r < 0) {
-                log_error("Failed to seek to head: %s", strerror(-r));
-                goto finish;
+        if (arg_lines >= 0) {
+                r = sd_journal_seek_tail(j);
+                if (r < 0) {
+                        log_error("Failed to seek to tail: %s", strerror(-r));
+                        goto finish;
+                }
+
+                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;
+                }
         }
 
         if (!arg_no_pager && !arg_follow) {

commit 8e9e6d567a5a9185b6f65adf3d9d1901ce25131f
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Jan 4 02:13:41 2012 +0100

    sd128: rename SD_FORMAT_ID128_STR to SD_ID128_FORMAT_STR to follow naming scheme

diff --git a/src/sd-id128.h b/src/sd-id128.h
index 2ae1002..d835cf4 100644
--- a/src/sd-id128.h
+++ b/src/sd-id128.h
@@ -49,12 +49,12 @@ int sd_id128_get_boot(sd_id128_t *ret);
         ((sd_id128_t) { .bytes = { 0x##v0, 0x##v1, 0x##v2, 0x##v3, 0x##v4, 0x##v5, 0x##v6, 0x##v7, \
                                    0x##v8, 0x##v9, 0x##v10, 0x##v11, 0x##v12, 0x##v13, 0x##v14, 0x##v15 }})
 
-/* Note that SD_FORMAT_ID128_VAL will evaluate the passed argument 16
+/* Note that SD_ID128_FORMAT_VAL will evaluate the passed argument 16
  * times. It is hence not a good idea to call this macro with an
  * expensive function as paramater or an expression with side
  * effects */
-#define SD_FORMAT_ID128_STR "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
-#define SD_FORMAT_ID128_VAL(x) (x).bytes[0], (x).bytes[1], (x).bytes[2], (x).bytes[3], (x).bytes[4], (x).bytes[5], (x).bytes[6], (x).bytes[7], (x).bytes[8], (x).bytes[9], (x).bytes[10], (x).bytes[11], (x).bytes[12], (x).bytes[13], (x).bytes[14], (x).bytes[15]
+#define SD_ID128_FORMAT_STR "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
+#define SD_ID128_FORMAT_VAL(x) (x).bytes[0], (x).bytes[1], (x).bytes[2], (x).bytes[3], (x).bytes[4], (x).bytes[5], (x).bytes[6], (x).bytes[7], (x).bytes[8], (x).bytes[9], (x).bytes[10], (x).bytes[11], (x).bytes[12], (x).bytes[13], (x).bytes[14], (x).bytes[15]
 
 static inline bool sd_id128_equal(sd_id128_t a, sd_id128_t b) {
         return memcmp(&a, &b, 16) == 0;
diff --git a/src/test-id128.c b/src/test-id128.c
index 520a496..d7c9d43 100644
--- a/src/test-id128.c
+++ b/src/test-id128.c
@@ -45,7 +45,7 @@ int main(int argc, char *argv[]) {
 
         printf("waldi: %s\n", sd_id128_to_string(ID128_WALDI, t));
 
-        printf("waldi2: " SD_FORMAT_ID128_STR "\n", SD_FORMAT_ID128_VAL(ID128_WALDI));
+        printf("waldi2: " SD_ID128_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(ID128_WALDI));
 
         return 0;
 }



More information about the systemd-commits mailing list