chiark / gitweb /
journald: don't choke on journal files with no cutoff date
[elogind.git] / src / journal / sd-journal.c
index 4bcc65c5c717c6c1e8b516e7c43aed9cd841b360..c3f19ca697a4396150c8c43d99b5dd4ee00822a0 100644 (file)
@@ -313,7 +313,7 @@ static char *match_make_string(Match *m) {
                 }
 
                 if (p) {
-                        k = join(p, m->type == MATCH_OR_TERM ? " OR " : " AND ", t, NULL);
+                        k = strjoin(p, m->type == MATCH_OR_TERM ? " OR " : " AND ", t, NULL);
                         free(p);
                         free(t);
 
@@ -330,7 +330,7 @@ static char *match_make_string(Match *m) {
         }
 
         if (enclose) {
-                r = join("(", p, ")", NULL);
+                r = strjoin("(", p, ")", NULL);
                 free(p);
                 return r;
         }
@@ -745,7 +745,7 @@ static int next_with_matches(
                 return journal_file_next_entry(f, c, cp, direction, ret, offset);
 
         /* If we have a match then we look for the next matching entry
-         * wiht an offset at least one step larger */
+         * with an offset at least one step larger */
         return next_for_match(j, j->level0, f, direction == DIRECTION_DOWN ? cp+1 : cp-1, direction, ret, offset);
 }
 
@@ -1101,7 +1101,7 @@ static int add_file(sd_journal *j, const char *prefix, const char *filename) {
              (startswith(filename, "system@") && endswith(filename, ".journal"))))
                 return 0;
 
-        path = join(prefix, "/", filename, NULL);
+        path = strjoin(prefix, "/", filename, NULL);
         if (!path)
                 return -ENOMEM;
 
@@ -1116,7 +1116,7 @@ static int add_file(sd_journal *j, const char *prefix, const char *filename) {
                 return 0;
         }
 
-        r = journal_file_open(path, O_RDONLY, 0, NULL, &f);
+        r = journal_file_open(path, O_RDONLY, 0, NULL, NULL, &f);
         free(path);
 
         if (r < 0) {
@@ -1149,7 +1149,7 @@ static int remove_file(sd_journal *j, const char *prefix, const char *filename)
         assert(prefix);
         assert(filename);
 
-        path = join(prefix, "/", filename, NULL);
+        path = strjoin(prefix, "/", filename, NULL);
         if (!path)
                 return -ENOMEM;
 
@@ -1184,7 +1184,7 @@ static int add_directory(sd_journal *j, const char *prefix, const char *dirname)
              !sd_id128_equal(id, mid)))
             return 0;
 
-        path = join(prefix, "/", dirname, NULL);
+        path = strjoin(prefix, "/", dirname, NULL);
         if (!path)
                 return -ENOMEM;
 
@@ -1868,7 +1868,7 @@ static int determine_change(sd_journal *j) {
 }
 
 _public_ int sd_journal_process(sd_journal *j) {
-        uint8_t buffer[sizeof(struct inotify_event) + FILENAME_MAX];
+        uint8_t buffer[sizeof(struct inotify_event) + FILENAME_MAX] _alignas_(struct inotify_event);
         bool got_something = false;
 
         if (!j)
@@ -1950,6 +1950,8 @@ _public_ int sd_journal_get_cutoff_realtime_usec(sd_journal *j, uint64_t *from,
                 usec_t fr, t;
 
                 r = journal_file_get_cutoff_realtime_usec(f, &fr, &t);
+                if (r == -ENOENT)
+                        continue;
                 if (r < 0)
                         return r;
                 if (r == 0)
@@ -1987,6 +1989,8 @@ _public_ int sd_journal_get_cutoff_monotonic_usec(sd_journal *j, sd_id128_t boot
                 usec_t fr, t;
 
                 r = journal_file_get_cutoff_monotonic_usec(f, boot_id, &fr, &t);
+                if (r == -ENOENT)
+                        continue;
                 if (r < 0)
                         return r;
                 if (r == 0)
@@ -2009,6 +2013,22 @@ _public_ int sd_journal_get_cutoff_monotonic_usec(sd_journal *j, sd_id128_t boot
         return first ? 0 : 1;
 }
 
+void journal_print_header(sd_journal *j) {
+        Iterator i;
+        JournalFile *f;
+        bool newline = false;
+
+        assert(j);
+
+        HASHMAP_FOREACH(f, j->files, i) {
+                if (newline)
+                        putchar('\n');
+                else
+                        newline = true;
+
+                journal_file_print_header(f);
+        }
+}
 
 /* _public_ int sd_journal_query_unique(sd_journal *j, const char *field) { */
 /*         if (!j) */