X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjournal%2Fcatalog.c;h=6b195f6920a16de5418cfdbfe883c6d7ea455fc2;hb=2e8fb7026d3c560194cfe9f83935ce0b16263da0;hp=22029da8518893ef0197e5bfc489addf49a0598c;hpb=7c670f5b44a6e8758918eaacd59f472ee7942514;p=elogind.git diff --git a/src/journal/catalog.c b/src/journal/catalog.c index 22029da85..6b195f692 100644 --- a/src/journal/catalog.c +++ b/src/journal/catalog.c @@ -269,7 +269,6 @@ static int import_file(Hashmap *h, struct strbuf *sb, const char *path) { return 0; } -#define CATALOG_PATH "/var/lib/systemd/catalog" #define CATALOG_DATABASE CATALOG_PATH "/database" int catalog_update(void) { @@ -297,7 +296,7 @@ int catalog_update(void) { goto finish; } - r = conf_files_list_strv(&files, ".catalog", (const char **) conf_file_dirs); + r = conf_files_list_strv(&files, ".catalog", NULL, (const char **) conf_file_dirs); if (r < 0) { log_error("Failed to get catalog files: %s", strerror(-r)); goto finish; @@ -384,7 +383,7 @@ int catalog_update(void) { goto finish; } - log_debug("%s: wrote %u items, with %zu bytes of strings, %zu total size.", + log_debug("%s: wrote %u items, with %zu bytes of strings, %ld total size.", CATALOG_DATABASE, n, sb->len, ftell(w)); free(p); @@ -414,7 +413,7 @@ static int open_mmap(int *_fd, struct stat *_st, void **_p) { assert(_st); assert(_p); - fd = open("/var/lib/systemd/catalog/database", O_RDONLY|O_CLOEXEC); + fd = open(CATALOG_DATABASE, O_RDONLY|O_CLOEXEC); if (fd < 0) return -errno; @@ -552,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; @@ -572,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; @@ -592,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(-k)); + 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(-k)); + if (r < 0) + r = k; + continue; + } + + dump_catalog_entry(f, id, msg, oneline); + } + + return r; +}