X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fjournal%2Fcatalog.c;h=03dddb48a55d86469880eaef9d150440289fca17;hp=f03357dedf9bc87ca84a28873d7e330282eae981;hb=eb56eb9b40950f1edcffdb7313f8de4f8572a6d5;hpb=baf167ee0a2953f98e4e7d4c35752ef737832674 diff --git a/src/journal/catalog.c b/src/journal/catalog.c index f03357ded..03dddb48a 100644 --- a/src/journal/catalog.c +++ b/src/journal/catalog.c @@ -64,7 +64,7 @@ typedef struct CatalogItem { le64_t offset; } CatalogItem; -unsigned long catalog_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]) { +static unsigned long catalog_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]) { const CatalogItem *i = p; uint64_t u; size_t l, sz; @@ -81,7 +81,7 @@ unsigned long catalog_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_S return (unsigned long) u; } -int catalog_compare_func(const void *a, const void *b) { +static int catalog_compare_func(const void *a, const void *b) { const CatalogItem *i = a, *j = b; unsigned k; @@ -95,6 +95,11 @@ int catalog_compare_func(const void *a, const void *b) { return strcmp(i->language, j->language); } +const struct hash_ops catalog_hash_ops = { + .hash = catalog_hash_func, + .compare = catalog_compare_func +}; + static int finish_item( Hashmap *h, struct strbuf *sb, @@ -336,17 +341,13 @@ static long write_catalog(const char *database, Hashmap *h, struct strbuf *sb, return log_oom(); r = mkdir_p(d, 0775); - if (r < 0) { - log_error("Recursive mkdir %s: %s", d, strerror(-r)); - return r; - } + if (r < 0) + return log_error_errno(r, "Recursive mkdir %s: %m", d); r = fopen_temporary(database, &w, &p); - if (r < 0) { - log_error("Failed to open database for writing: %s: %s", - database, strerror(-r)); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to open database for writing: %s: %m", + database); zero(header); memcpy(header.signature, CATALOG_SIGNATURE, sizeof(header.signature)); @@ -407,7 +408,7 @@ int catalog_update(const char* database, const char* root, const char* const* di unsigned n; long r; - h = hashmap_new(catalog_hash_func, catalog_compare_func); + h = hashmap_new(&catalog_hash_ops); sb = strbuf_new(); if (!h || !sb) { @@ -417,7 +418,7 @@ int catalog_update(const char* database, const char* root, const char* const* di r = conf_files_list_strv(&files, ".catalog", root, dirs); if (r < 0) { - log_error("Failed to get catalog files: %s", strerror(-r)); + log_error_errno(r, "Failed to get catalog files: %m"); goto finish; } @@ -458,7 +459,7 @@ int catalog_update(const char* database, const char* root, const char* const* di r = write_catalog(database, h, sb, items, n); if (r < 0) - log_error("Failed to write %s: %s", database, strerror(-r)); + log_error_errno(r, "Failed to write %s: %m", database); else log_debug("%s: wrote %u items, with %zu bytes of strings, %ld total size.", database, n, sb->len, r); @@ -682,8 +683,8 @@ int catalog_list_items(FILE *f, const char *database, bool oneline, char **items k = sd_id128_from_string(*item, &id); if (k < 0) { - log_error("Failed to parse id128 '%s': %s", - *item, strerror(-k)); + log_error_errno(k, "Failed to parse id128 '%s': %m", + *item); if (r == 0) r = k; continue;