summaryrefslogtreecommitdiff
path: root/src/journal/catalog.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-03-19 20:54:04 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-03-19 21:50:43 -0400
commit54b7254c1fa629937f92fd6fa34bdf127b696a00 (patch)
treee86537d15eb74b4a6ecc5bd2cfc0dd5aeaf17489 /src/journal/catalog.c
parentab3a162c0194fd92884798488eeafdcc5c4d7d57 (diff)
journalct: beef up entry listing
The ability to dump catalog entries in full and by id is added.
Diffstat (limited to 'src/journal/catalog.c')
-rw-r--r--src/journal/catalog.c58
1 files changed, 52 insertions, 6 deletions
diff --git a/src/journal/catalog.c b/src/journal/catalog.c
index 32256f6263..dacf5c50a1 100644
--- a/src/journal/catalog.c
+++ b/src/journal/catalog.c
@@ -551,7 +551,23 @@ static char *find_header(const char *s, const char *header) {
}
}
-int catalog_list(FILE *f) {
+static void dump_catalog_entry(FILE *f, sd_id128_t id, const char *s, bool oneline) {
+ if (oneline) {
+ _cleanup_free_ char *subject = NULL, *defined_by = NULL;
+
+ subject = find_header(s, "Subject:");
+ defined_by = find_header(s, "Defined-By:");
+
+ fprintf(f, SD_ID128_FORMAT_STR " %s: %s\n",
+ SD_ID128_FORMAT_VAL(id),
+ strna(defined_by), strna(subject));
+ } else
+ fprintf(f, "-- " SD_ID128_FORMAT_STR "\n%s\n",
+ SD_ID128_FORMAT_VAL(id), s);
+}
+
+
+int catalog_list(FILE *f, bool oneline) {
_cleanup_close_ int fd = -1;
void *p = NULL;
struct stat st;
@@ -571,17 +587,13 @@ int catalog_list(FILE *f) {
for (n = 0; n < le64toh(h->n_items); n++) {
const char *s;
- _cleanup_free_ char *subject = NULL, *defined_by = NULL;
if (last_id_set && sd_id128_equal(last_id, items[n].id))
continue;
assert_se(s = find_id(p, items[n].id));
- subject = find_header(s, "Subject:");
- defined_by = find_header(s, "Defined-By:");
-
- fprintf(f, SD_ID128_FORMAT_STR " %s: %s\n", SD_ID128_FORMAT_VAL(items[n].id), strna(defined_by), strna(subject));
+ dump_catalog_entry(f, items[n].id, s, oneline);
last_id_set = true;
last_id = items[n].id;
@@ -591,3 +603,37 @@ int catalog_list(FILE *f) {
return 0;
}
+
+int catalog_list_items(FILE *f, bool oneline, char **items) {
+ char **item;
+ int r = 0;
+
+ STRV_FOREACH(item, items) {
+ sd_id128_t id;
+ int k;
+ char _cleanup_free_ *msg = NULL;
+
+ k = sd_id128_from_string(*item, &id);
+ if (k < 0) {
+ log_error("Failed to parse id128 '%s': %s",
+ *item, strerror(-r));
+ if (r < 0)
+ r = k;
+ continue;
+ }
+
+ k = catalog_get(id, &msg);
+ if (k < 0) {
+ log_full(k == -ENOENT ? LOG_NOTICE : LOG_ERR,
+ "Failed to retrieve catalog entry for '%s': %s",
+ *item, strerror(-r));
+ if (r < 0)
+ r = k;
+ continue;
+ }
+
+ dump_catalog_entry(f, id, msg, oneline);
+ }
+
+ return r;
+}