chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
update TODO
[elogind.git]
/
src
/
journal
/
catalog.c
diff --git
a/src/journal/catalog.c
b/src/journal/catalog.c
index f03357dedf9bc87ca84a28873d7e330282eae981..f1702328419dfa52033b450d2dba054438a6f7a5 100644
(file)
--- a/
src/journal/catalog.c
+++ b/
src/journal/catalog.c
@@
-26,7
+26,6
@@
#include <string.h>
#include <sys/mman.h>
#include <locale.h>
#include <string.h>
#include <sys/mman.h>
#include <locale.h>
-#include <libgen.h>
#include "util.h"
#include "log.h"
#include "util.h"
#include "log.h"
@@
-64,7
+63,7
@@
typedef struct CatalogItem {
le64_t offset;
} 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;
const CatalogItem *i = p;
uint64_t u;
size_t l, sz;
@@
-81,7
+80,7
@@
unsigned long catalog_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_S
return (unsigned long) u;
}
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;
const CatalogItem *i = a, *j = b;
unsigned k;
@@
-95,6
+94,11
@@
int catalog_compare_func(const void *a, const void *b) {
return strcmp(i->language, j->language);
}
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,
static int finish_item(
Hashmap *h,
struct strbuf *sb,
@@
-204,14
+208,12
@@
int catalog_import_file(Hashmap *h, struct strbuf *sb, const char *path) {
assert(path);
f = fopen(path, "re");
assert(path);
f = fopen(path, "re");
- if (!f) {
- log_error("Failed to open file %s: %m", path);
- return -errno;
- }
+ if (!f)
+ return log_error_errno(errno, "Failed to open file %s: %m", path);
r = catalog_file_lang(path, &deflang);
if (r < 0)
r = catalog_file_lang(path, &deflang);
if (r < 0)
- log_error
(
"Failed to determine language for file %s: %m", path);
+ log_error
_errno(errno,
"Failed to determine language for file %s: %m", path);
if (r == 1)
log_debug("File %s has language %s.", path, deflang);
if (r == 1)
log_debug("File %s has language %s.", path, deflang);
@@
-224,7
+226,7
@@
int catalog_import_file(Hashmap *h, struct strbuf *sb, const char *path) {
if (feof(f))
break;
if (feof(f))
break;
- log_error
(
"Failed to read file %s: %m", path);
+ log_error
_errno(errno,
"Failed to read file %s: %m", path);
return -errno;
}
return -errno;
}
@@
-336,17
+338,13
@@
static long write_catalog(const char *database, Hashmap *h, struct strbuf *sb,
return log_oom();
r = mkdir_p(d, 0775);
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);
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));
zero(header);
memcpy(header.signature, CATALOG_SIGNATURE, sizeof(header.signature));
@@
-384,7
+382,7
@@
static long write_catalog(const char *database, Hashmap *h, struct strbuf *sb,
fchmod(fileno(w), 0644);
if (rename(p, database) < 0) {
fchmod(fileno(w), 0644);
if (rename(p, database) < 0) {
- log_error
(
"rename (%s -> %s) failed: %m", p, database);
+ log_error
_errno(errno,
"rename (%s -> %s) failed: %m", p, database);
r = -errno;
goto error;
}
r = -errno;
goto error;
}
@@
-407,7
+405,7
@@
int catalog_update(const char* database, const char* root, const char* const* di
unsigned n;
long r;
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) {
sb = strbuf_new();
if (!h || !sb) {
@@
-417,7
+415,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) {
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;
}
goto finish;
}
@@
-458,7
+456,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)
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);
else
log_debug("%s: wrote %u items, with %zu bytes of strings, %ld total size.",
database, n, sb->len, r);
@@
-682,8
+680,8
@@
int catalog_list_items(FILE *f, const char *database, bool oneline, char **items
k = sd_id128_from_string(*item, &id);
if (k < 0) {
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;
if (r == 0)
r = k;
continue;