chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
journalctl: include corrupted files in output
[elogind.git]
/
src
/
journal
/
sd-journal.c
diff --git
a/src/journal/sd-journal.c
b/src/journal/sd-journal.c
index 4bcc65c5c717c6c1e8b516e7c43aed9cd841b360..33686ed2b26529793f78b8f8d924bfff4abd9d25 100644
(file)
--- a/
src/journal/sd-journal.c
+++ b/
src/journal/sd-journal.c
@@
-313,7
+313,7
@@
static char *match_make_string(Match *m) {
}
if (p) {
}
if (p) {
- k = join(p, m->type == MATCH_OR_TERM ? " OR " : " AND ", t, NULL);
+ k =
str
join(p, m->type == MATCH_OR_TERM ? " OR " : " AND ", t, NULL);
free(p);
free(t);
free(p);
free(t);
@@
-330,7
+330,7
@@
static char *match_make_string(Match *m) {
}
if (enclose) {
}
if (enclose) {
- r = join("(", p, ")", NULL);
+ r =
str
join("(", p, ")", NULL);
free(p);
return r;
}
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
return journal_file_next_entry(f, c, cp, direction, ret, offset);
/* If we have a match then we look for the next matching entry
- * wi
ht
an offset at least one step larger */
+ * wi
th
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);
}
return next_for_match(j, j->level0, f, direction == DIRECTION_DOWN ? cp+1 : cp-1, direction, ret, offset);
}
@@
-1098,10
+1098,12
@@
static int add_file(sd_journal *j, const char *prefix, const char *filename) {
if ((j->flags & SD_JOURNAL_SYSTEM_ONLY) &&
!(streq(filename, "system.journal") ||
if ((j->flags & SD_JOURNAL_SYSTEM_ONLY) &&
!(streq(filename, "system.journal") ||
- (startswith(filename, "system@") && endswith(filename, ".journal"))))
+ streq(filename, "system.journal~") ||
+ (startswith(filename, "system@") &&
+ (endswith(filename, ".journal") || endswith(filename, ".journal~")))))
return 0;
return 0;
- path = join(prefix, "/", filename, NULL);
+ path =
str
join(prefix, "/", filename, NULL);
if (!path)
return -ENOMEM;
if (!path)
return -ENOMEM;
@@
-1116,7
+1118,7
@@
static int add_file(sd_journal *j, const char *prefix, const char *filename) {
return 0;
}
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) {
free(path);
if (r < 0) {
@@
-1149,7
+1151,7
@@
static int remove_file(sd_journal *j, const char *prefix, const char *filename)
assert(prefix);
assert(filename);
assert(prefix);
assert(filename);
- path = join(prefix, "/", filename, NULL);
+ path =
str
join(prefix, "/", filename, NULL);
if (!path)
return -ENOMEM;
if (!path)
return -ENOMEM;
@@
-1184,7
+1186,7
@@
static int add_directory(sd_journal *j, const char *prefix, const char *dirname)
!sd_id128_equal(id, mid)))
return 0;
!sd_id128_equal(id, mid)))
return 0;
- path = join(prefix, "/", dirname, NULL);
+ path =
str
join(prefix, "/", dirname, NULL);
if (!path)
return -ENOMEM;
if (!path)
return -ENOMEM;
@@
-1233,7
+1235,7
@@
static int add_directory(sd_journal *j, const char *prefix, const char *dirname)
m->wd = inotify_add_watch(j->inotify_fd, m->path,
IN_CREATE|IN_MOVED_TO|IN_MODIFY|IN_ATTRIB|IN_DELETE|
IN_DELETE_SELF|IN_MOVE_SELF|IN_UNMOUNT|
m->wd = inotify_add_watch(j->inotify_fd, m->path,
IN_CREATE|IN_MOVED_TO|IN_MODIFY|IN_ATTRIB|IN_DELETE|
IN_DELETE_SELF|IN_MOVE_SELF|IN_UNMOUNT|
- IN_
DONT_FOLLOW|IN_
ONLYDIR);
+ IN_ONLYDIR);
if (m->wd > 0 && hashmap_put(j->directories_by_wd, INT_TO_PTR(m->wd), m) < 0)
inotify_rm_watch(j->inotify_fd, m->wd);
if (m->wd > 0 && hashmap_put(j->directories_by_wd, INT_TO_PTR(m->wd), m) < 0)
inotify_rm_watch(j->inotify_fd, m->wd);
@@
-1246,7
+1248,8
@@
static int add_directory(sd_journal *j, const char *prefix, const char *dirname)
if (r != 0 || !de)
break;
if (r != 0 || !de)
break;
- if (dirent_is_file_with_suffix(de, ".journal")) {
+ if (dirent_is_file_with_suffix(de, ".journal") ||
+ dirent_is_file_with_suffix(de, ".journal~")) {
r = add_file(j, m->path, de->d_name);
if (r < 0)
log_debug("Failed to add file %s/%s: %s", m->path, de->d_name, strerror(-r));
r = add_file(j, m->path, de->d_name);
if (r < 0)
log_debug("Failed to add file %s/%s: %s", m->path, de->d_name, strerror(-r));
@@
-1310,7
+1313,7
@@
static int add_root_directory(sd_journal *j, const char *p) {
m->wd = inotify_add_watch(j->inotify_fd, m->path,
IN_CREATE|IN_MOVED_TO|IN_MODIFY|IN_ATTRIB|IN_DELETE|
m->wd = inotify_add_watch(j->inotify_fd, m->path,
IN_CREATE|IN_MOVED_TO|IN_MODIFY|IN_ATTRIB|IN_DELETE|
- IN_
DONT_FOLLOW|IN_
ONLYDIR);
+ IN_ONLYDIR);
if (m->wd > 0 && hashmap_put(j->directories_by_wd, INT_TO_PTR(m->wd), m) < 0)
inotify_rm_watch(j->inotify_fd, m->wd);
if (m->wd > 0 && hashmap_put(j->directories_by_wd, INT_TO_PTR(m->wd), m) < 0)
inotify_rm_watch(j->inotify_fd, m->wd);
@@
-1324,12
+1327,13
@@
static int add_root_directory(sd_journal *j, const char *p) {
if (r != 0 || !de)
break;
if (r != 0 || !de)
break;
- if (dirent_is_file_with_suffix(de, ".journal")) {
+ if (dirent_is_file_with_suffix(de, ".journal") ||
+ dirent_is_file_with_suffix(de, ".journal~")) {
r = add_file(j, m->path, de->d_name);
if (r < 0)
log_debug("Failed to add file %s/%s: %s", m->path, de->d_name, strerror(-r));
r = add_file(j, m->path, de->d_name);
if (r < 0)
log_debug("Failed to add file %s/%s: %s", m->path, de->d_name, strerror(-r));
- } else if ((de->d_type == DT_DIR || de->d_type == DT_UNKNOWN) &&
+ } else if ((de->d_type == DT_DIR || de->d_type == DT_
LNK || de->d_type == DT_
UNKNOWN) &&
sd_id128_from_string(de->d_name, &id) >= 0) {
r = add_directory(j, m->path, de->d_name);
sd_id128_from_string(de->d_name, &id) >= 0) {
r = add_directory(j, m->path, de->d_name);
@@
-1402,7
+1406,7
@@
static int allocate_inotify(sd_journal *j) {
return 0;
}
return 0;
}
-static sd_journal *journal_new(int flags) {
+static sd_journal *journal_new(int flags
, const char *path
) {
sd_journal *j;
j = new0(sd_journal, 1);
sd_journal *j;
j = new0(sd_journal, 1);
@@
-1412,8
+1416,17
@@
static sd_journal *journal_new(int flags) {
j->inotify_fd = -1;
j->flags = flags;
j->inotify_fd = -1;
j->flags = flags;
+ if (path) {
+ j->path = strdup(path);
+ if (!j->path) {
+ free(j);
+ return NULL;
+ }
+ }
+
j->files = hashmap_new(string_hash_func, string_compare_func);
if (!j->files) {
j->files = hashmap_new(string_hash_func, string_compare_func);
if (!j->files) {
+ free(j->path);
free(j);
return NULL;
}
free(j);
return NULL;
}
@@
-1421,6
+1434,7
@@
static sd_journal *journal_new(int flags) {
j->directories_by_path = hashmap_new(string_hash_func, string_compare_func);
if (!j->directories_by_path) {
hashmap_free(j->files);
j->directories_by_path = hashmap_new(string_hash_func, string_compare_func);
if (!j->directories_by_path) {
hashmap_free(j->files);
+ free(j->path);
free(j);
return NULL;
}
free(j);
return NULL;
}
@@
-1440,7
+1454,7
@@
_public_ int sd_journal_open(sd_journal **ret, int flags) {
SD_JOURNAL_SYSTEM_ONLY))
return -EINVAL;
SD_JOURNAL_SYSTEM_ONLY))
return -EINVAL;
- j = journal_new(flags);
+ j = journal_new(flags
, NULL
);
if (!j)
return -ENOMEM;
if (!j)
return -ENOMEM;
@@
-1470,7
+1484,7
@@
_public_ int sd_journal_open_directory(sd_journal **ret, const char *path, int f
if (flags != 0)
return -EINVAL;
if (flags != 0)
return -EINVAL;
- j = journal_new(flags);
+ j = journal_new(flags
, path
);
if (!j)
return -ENOMEM;
if (!j)
return -ENOMEM;
@@
-1513,6
+1527,7
@@
_public_ void sd_journal_close(sd_journal *j) {
sd_journal_flush_matches(j);
sd_journal_flush_matches(j);
+ free(j->path);
free(j);
}
free(j);
}
@@
-1790,7
+1805,10
@@
_public_ int sd_journal_get_fd(sd_journal *j) {
/* Iterate through all dirs again, to add them to the
* inotify */
/* Iterate through all dirs again, to add them to the
* inotify */
- r = add_search_paths(j);
+ if (j->path)
+ r = add_root_directory(j, j->path);
+ else
+ r = add_search_paths(j);
if (r < 0)
return r;
if (r < 0)
return r;
@@
-1809,7
+1827,9
@@
static void process_inotify_event(sd_journal *j, struct inotify_event *e) {
if (d) {
sd_id128_t id;
if (d) {
sd_id128_t id;
- if (!(e->mask & IN_ISDIR) && e->len > 0 && endswith(e->name, ".journal")) {
+ if (!(e->mask & IN_ISDIR) && e->len > 0 &&
+ (endswith(e->name, ".journal") ||
+ endswith(e->name, ".journal~"))) {
/* Event for a journal file */
/* Event for a journal file */
@@
-1868,7
+1888,7
@@
static int determine_change(sd_journal *j) {
}
_public_ int sd_journal_process(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)
bool got_something = false;
if (!j)
@@
-1950,6
+1970,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);
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)
if (r < 0)
return r;
if (r == 0)
@@
-1987,6
+2009,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);
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)
if (r < 0)
return r;
if (r == 0)
@@
-2009,6
+2033,22
@@
_public_ int sd_journal_get_cutoff_monotonic_usec(sd_journal *j, sd_id128_t boot
return first ? 0 : 1;
}
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) */
/* _public_ int sd_journal_query_unique(sd_journal *j, const char *field) { */
/* if (!j) */