chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
hashmap: hashmap_move_one() should return -ENOENT when 'other' is NULL
[elogind.git]
/
src
/
journal
/
sd-journal.c
diff --git
a/src/journal/sd-journal.c
b/src/journal/sd-journal.c
index 693707cb347a817da8f2a416e29ba5dfe6d30aa2..ac57f4f6f8942f28d6ff9469f6d132e97487da16 100644
(file)
--- a/
src/journal/sd-journal.c
+++ b/
src/journal/sd-journal.c
@@
-70,7
+70,7
@@
static int set_put_error(sd_journal *j, int r) {
if (r >= 0)
return r;
if (r >= 0)
return r;
- k = set_ensure_allocated(&j->errors,
trivial_hash_func, trivial_compare_func
);
+ k = set_ensure_allocated(&j->errors,
NULL
);
if (k < 0)
return k;
if (k < 0)
return k;
@@
-849,10
+849,8
@@
static int next_beyond_location(sd_journal *j, JournalFile *f, direction_t direc
int k;
k = compare_with_location(f, c, &j->current_location);
int k;
k = compare_with_location(f, c, &j->current_location);
- if (direction == DIRECTION_DOWN)
- found = k > 0;
- else
- found = k < 0;
+
+ found = direction == DIRECTION_DOWN ? k > 0 : k < 0;
} else
found = true;
} else
found = true;
@@
-1375,8
+1373,11
@@
static void remove_file_real(sd_journal *j, JournalFile *f) {
}
if (j->unique_file == f) {
}
if (j->unique_file == f) {
- j->unique_file = NULL;
+ /* Jump to the next unique_file or NULL if that one was last */
+ j->unique_file = hashmap_next(j->files, j->unique_file->path);
j->unique_offset = 0;
j->unique_offset = 0;
+ if (!j->unique_file)
+ j->unique_file_lost = true;
}
journal_file_close(f);
}
journal_file_close(f);
@@
-1662,7
+1663,7
@@
static int allocate_inotify(sd_journal *j) {
}
if (!j->directories_by_wd) {
}
if (!j->directories_by_wd) {
- j->directories_by_wd = hashmap_new(
trivial_hash_func, trivial_compare_func
);
+ j->directories_by_wd = hashmap_new(
NULL
);
if (!j->directories_by_wd)
return -ENOMEM;
}
if (!j->directories_by_wd)
return -ENOMEM;
}
@@
-1688,8
+1689,8
@@
static sd_journal *journal_new(int flags, const char *path) {
goto fail;
}
goto fail;
}
- j->files = hashmap_new(
string_hash_func, string_compare_func
);
- j->directories_by_path = hashmap_new(
string_hash_func, string_compare_func
);
+ j->files = hashmap_new(
&string_hash_ops
);
+ j->directories_by_path = hashmap_new(
&string_hash_ops
);
j->mmap = mmap_cache_new();
if (!j->files || !j->directories_by_path || !j->mmap)
goto fail;
j->mmap = mmap_cache_new();
if (!j->files || !j->directories_by_path || !j->mmap)
goto fail;
@@
-1734,7
+1735,7
@@
_public_ int sd_journal_open_container(sd_journal **ret, const char *machine, in
assert_return(machine, -EINVAL);
assert_return(ret, -EINVAL);
assert_return((flags & ~(SD_JOURNAL_LOCAL_ONLY|SD_JOURNAL_SYSTEM)) == 0, -EINVAL);
assert_return(machine, -EINVAL);
assert_return(ret, -EINVAL);
assert_return((flags & ~(SD_JOURNAL_LOCAL_ONLY|SD_JOURNAL_SYSTEM)) == 0, -EINVAL);
- assert_return(
filename_is_safe
(machine), -EINVAL);
+ assert_return(
machine_name_is_valid
(machine), -EINVAL);
p = strappenda("/run/systemd/machines/", machine);
r = parse_env_file(p, NEWLINE, "ROOT", &root, "CLASS", &class, NULL);
p = strappenda("/run/systemd/machines/", machine);
r = parse_env_file(p, NEWLINE, "ROOT", &root, "CLASS", &class, NULL);
@@
-2490,6
+2491,7
@@
_public_ int sd_journal_query_unique(sd_journal *j, const char *field) {
j->unique_field = f;
j->unique_file = NULL;
j->unique_offset = 0;
j->unique_field = f;
j->unique_file = NULL;
j->unique_offset = 0;
+ j->unique_file_lost = false;
return 0;
}
return 0;
}
@@
-2506,9
+2508,13
@@
_public_ int sd_journal_enumerate_unique(sd_journal *j, const void **data, size_
k = strlen(j->unique_field);
if (!j->unique_file) {
k = strlen(j->unique_field);
if (!j->unique_file) {
+ if (j->unique_file_lost)
+ return 0;
+
j->unique_file = hashmap_first(j->files);
if (!j->unique_file)
return 0;
j->unique_file = hashmap_first(j->files);
if (!j->unique_file)
return 0;
+
j->unique_offset = 0;
}
j->unique_offset = 0;
}
@@
-2520,6
+2526,7
@@
_public_ int sd_journal_enumerate_unique(sd_journal *j, const void **data, size_
size_t ol;
bool found;
int r;
size_t ol;
bool found;
int r;
+ void *release_cookie;
/* Proceed to next data object in the field's linked list */
if (j->unique_offset == 0) {
/* Proceed to next data object in the field's linked list */
if (j->unique_offset == 0) {
@@
-2538,13
+2545,10
@@
_public_ int sd_journal_enumerate_unique(sd_journal *j, const void **data, size_
/* We reached the end of the list? Then start again, with the next file */
if (j->unique_offset == 0) {
/* We reached the end of the list? Then start again, with the next file */
if (j->unique_offset == 0) {
- JournalFile *n;
-
- n = hashmap_next(j->files, j->unique_file->path);
- if (!n)
+ j->unique_file = hashmap_next(j->files, j->unique_file->path);
+ if (!j->unique_file)
return 0;
return 0;
- j->unique_file = n;
continue;
}
continue;
}
@@
-2563,7
+2567,7
@@
_public_ int sd_journal_enumerate_unique(sd_journal *j, const void **data, size_
return -EBADMSG;
}
return -EBADMSG;
}
- r = journal_file_object_keep(j->unique_file, o, j->unique_offset);
+ r = journal_file_object_keep(j->unique_file, o, j->unique_offset
, &release_cookie
);
if (r < 0)
return r;
if (r < 0)
return r;
@@
-2611,13
+2615,13
@@
_public_ int sd_journal_enumerate_unique(sd_journal *j, const void **data, size_
found = true;
}
found = true;
}
- if (found)
- continue;
-
- r = journal_file_object_release(j->unique_file, o, j->unique_offset);
+ r = journal_file_object_release(j->unique_file, release_cookie);
if (r < 0)
return r;
if (r < 0)
return r;
+ if (found)
+ continue;
+
r = return_data(j, j->unique_file, o, data, l);
if (r < 0)
return r;
r = return_data(j, j->unique_file, o, data, l);
if (r < 0)
return r;
@@
-2632,6
+2636,7
@@
_public_ void sd_journal_restart_unique(sd_journal *j) {
j->unique_file = NULL;
j->unique_offset = 0;
j->unique_file = NULL;
j->unique_offset = 0;
+ j->unique_file_lost = false;
}
_public_ int sd_journal_reliable_fd(sd_journal *j) {
}
_public_ int sd_journal_reliable_fd(sd_journal *j) {