tree-wide: set SD_JOURNAL_ASSUME_IMMUTABLE where appropriate

Co-authored-by: Costa Tsaousis <costa@netdata.cloud>
This commit is contained in:
Yu Watanabe
2024-02-12 02:42:36 +09:00
co-authored by Costa Tsaousis
parent bd1af1d5fb
commit f7f062bf9f
15 changed files with 49 additions and 42 deletions
@@ -15,7 +15,7 @@ int main(int argc, char *argv[]) {
test_setup_logging(LOG_DEBUG);
assert_se(sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY) >= 0);
assert_se(sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY | SD_JOURNAL_ASSUME_IMMUTABLE) >= 0);
assert_se(sd_journal_add_match(j, "_TRANSPORT=syslog", 0) >= 0);
assert_se(sd_journal_add_match(j, "_UID=0", 0) >= 0);
@@ -36,9 +36,9 @@ static void test_journal_flush_one(int argc, char *argv[]) {
assert_se(r >= 0);
if (argc > 1)
r = sd_journal_open_files(&j, (const char **) strv_skip(argv, 1), 0);
r = sd_journal_open_files(&j, (const char **) strv_skip(argv, 1), SD_JOURNAL_ASSUME_IMMUTABLE);
else
r = sd_journal_open(&j, 0);
r = sd_journal_open(&j, SD_JOURNAL_ASSUME_IMMUTABLE);
assert_se(r == 0);
sd_journal_set_data_threshold(j, 0);
@@ -75,7 +75,7 @@ static void test_journal_flush_one(int argc, char *argv[]) {
/* Open the new journal before archiving and offlining the file. */
sd_journal_close(j);
assert_se(sd_journal_open_directory(&j, dn, 0) >= 0);
assert_se(sd_journal_open_directory(&j, dn, SD_JOURNAL_ASSUME_IMMUTABLE) >= 0);
/* Read the online journal. */
assert_se(sd_journal_seek_tail(j) >= 0);
@@ -31,12 +31,12 @@ int main(int argc, char *argv[]) {
(void) chattr_path(t, FS_NOCOW_FL, FS_NOCOW_FL, NULL);
for (i = 0; i < I; i++) {
r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY);
r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY | SD_JOURNAL_ASSUME_IMMUTABLE);
assert_se(r == 0);
sd_journal_close(j);
r = sd_journal_open_directory(&j, t, 0);
r = sd_journal_open_directory(&j, t, SD_JOURNAL_ASSUME_IMMUTABLE);
assert_se(r == 0);
assert_se(sd_journal_seek_head(j) == 0);
@@ -260,14 +260,14 @@ static void test_skip_one(void (*setup)(void)) {
setup();
/* Seek to head, iterate down. */
assert_ret(sd_journal_open_directory(&j, t, 0));
assert_ret(sd_journal_open_directory(&j, t, SD_JOURNAL_ASSUME_IMMUTABLE));
assert_ret(sd_journal_seek_head(j));
assert_se(sd_journal_next(j) == 1); /* pointing to the first entry */
test_check_numbers_down(j, 9);
sd_journal_close(j);
/* Seek to head, iterate down. */
assert_ret(sd_journal_open_directory(&j, t, 0));
assert_ret(sd_journal_open_directory(&j, t, SD_JOURNAL_ASSUME_IMMUTABLE));
assert_ret(sd_journal_seek_head(j));
assert_se(sd_journal_next(j) == 1); /* pointing to the first entry */
assert_se(sd_journal_previous(j) == 0); /* no-op */
@@ -275,7 +275,7 @@ static void test_skip_one(void (*setup)(void)) {
sd_journal_close(j);
/* Seek to head twice, iterate down. */
assert_ret(sd_journal_open_directory(&j, t, 0));
assert_ret(sd_journal_open_directory(&j, t, SD_JOURNAL_ASSUME_IMMUTABLE));
assert_ret(sd_journal_seek_head(j));
assert_se(sd_journal_next(j) == 1); /* pointing to the first entry */
assert_ret(sd_journal_seek_head(j));
@@ -284,7 +284,7 @@ static void test_skip_one(void (*setup)(void)) {
sd_journal_close(j);
/* Seek to head, move to previous, then iterate down. */
assert_ret(sd_journal_open_directory(&j, t, 0));
assert_ret(sd_journal_open_directory(&j, t, SD_JOURNAL_ASSUME_IMMUTABLE));
assert_ret(sd_journal_seek_head(j));
assert_se(sd_journal_previous(j) == 0); /* no-op */
assert_se(sd_journal_next(j) == 1); /* pointing to the first entry */
@@ -292,7 +292,7 @@ static void test_skip_one(void (*setup)(void)) {
sd_journal_close(j);
/* Seek to head, walk several steps, then iterate down. */
assert_ret(sd_journal_open_directory(&j, t, 0));
assert_ret(sd_journal_open_directory(&j, t, SD_JOURNAL_ASSUME_IMMUTABLE));
assert_ret(sd_journal_seek_head(j));
assert_se(sd_journal_previous(j) == 0); /* no-op */
assert_se(sd_journal_previous(j) == 0); /* no-op */
@@ -304,14 +304,14 @@ static void test_skip_one(void (*setup)(void)) {
sd_journal_close(j);
/* Seek to tail, iterate up. */
assert_ret(sd_journal_open_directory(&j, t, 0));
assert_ret(sd_journal_open_directory(&j, t, SD_JOURNAL_ASSUME_IMMUTABLE));
assert_ret(sd_journal_seek_tail(j));
assert_se(sd_journal_previous(j) == 1); /* pointing to the last entry */
test_check_numbers_up(j, 9);
sd_journal_close(j);
/* Seek to tail twice, iterate up. */
assert_ret(sd_journal_open_directory(&j, t, 0));
assert_ret(sd_journal_open_directory(&j, t, SD_JOURNAL_ASSUME_IMMUTABLE));
assert_ret(sd_journal_seek_tail(j));
assert_se(sd_journal_previous(j) == 1); /* pointing to the last entry */
assert_ret(sd_journal_seek_tail(j));
@@ -320,7 +320,7 @@ static void test_skip_one(void (*setup)(void)) {
sd_journal_close(j);
/* Seek to tail, move to next, then iterate up. */
assert_ret(sd_journal_open_directory(&j, t, 0));
assert_ret(sd_journal_open_directory(&j, t, SD_JOURNAL_ASSUME_IMMUTABLE));
assert_ret(sd_journal_seek_tail(j));
assert_se(sd_journal_next(j) == 0); /* no-op */
assert_se(sd_journal_previous(j) == 1); /* pointing to the last entry */
@@ -328,7 +328,7 @@ static void test_skip_one(void (*setup)(void)) {
sd_journal_close(j);
/* Seek to tail, walk several steps, then iterate up. */
assert_ret(sd_journal_open_directory(&j, t, 0));
assert_ret(sd_journal_open_directory(&j, t, SD_JOURNAL_ASSUME_IMMUTABLE));
assert_ret(sd_journal_seek_tail(j));
assert_se(sd_journal_next(j) == 0); /* no-op */
assert_se(sd_journal_next(j) == 0); /* no-op */
@@ -340,14 +340,14 @@ static void test_skip_one(void (*setup)(void)) {
sd_journal_close(j);
/* Seek to tail, skip to head, iterate down. */
assert_ret(sd_journal_open_directory(&j, t, 0));
assert_ret(sd_journal_open_directory(&j, t, SD_JOURNAL_ASSUME_IMMUTABLE));
assert_ret(sd_journal_seek_tail(j));
assert_se(sd_journal_previous_skip(j, 9) == 9); /* pointing to the first entry. */
test_check_numbers_down(j, 9);
sd_journal_close(j);
/* Seek to tail, skip to head in a more complex way, then iterate down. */
assert_ret(sd_journal_open_directory(&j, t, 0));
assert_ret(sd_journal_open_directory(&j, t, SD_JOURNAL_ASSUME_IMMUTABLE));
assert_ret(sd_journal_seek_tail(j));
assert_se(sd_journal_next(j) == 0);
assert_se(sd_journal_previous_skip(j, 4) == 4);
@@ -366,14 +366,14 @@ static void test_skip_one(void (*setup)(void)) {
sd_journal_close(j);
/* Seek to head, skip to tail, iterate up. */
assert_ret(sd_journal_open_directory(&j, t, 0));
assert_ret(sd_journal_open_directory(&j, t, SD_JOURNAL_ASSUME_IMMUTABLE));
assert_ret(sd_journal_seek_head(j));
assert_se(sd_journal_next_skip(j, 9) == 9);
test_check_numbers_up(j, 9);
sd_journal_close(j);
/* Seek to head, skip to tail in a more complex way, then iterate up. */
assert_ret(sd_journal_open_directory(&j, t, 0));
assert_ret(sd_journal_open_directory(&j, t, SD_JOURNAL_ASSUME_IMMUTABLE));
assert_ret(sd_journal_seek_head(j));
assert_se(sd_journal_previous(j) == 0);
assert_se(sd_journal_next_skip(j, 4) == 4);
@@ -409,14 +409,14 @@ static void test_boot_id_one(void (*setup)(void), size_t n_boots_expected) {
setup();
assert_ret(sd_journal_open_directory(&j, t, 0));
assert_ret(sd_journal_open_directory(&j, t, SD_JOURNAL_ASSUME_IMMUTABLE));
assert_se(journal_get_boots(j, &boots, &n_boots) >= 0);
assert_se(boots);
assert_se(n_boots == n_boots_expected);
sd_journal_close(j);
FOREACH_ARRAY(b, boots, n_boots) {
assert_ret(sd_journal_open_directory(&j, t, 0));
assert_ret(sd_journal_open_directory(&j, t, SD_JOURNAL_ASSUME_IMMUTABLE));
assert_se(journal_find_boot_by_id(j, b->id) == 1);
sd_journal_close(j);
}
@@ -424,7 +424,7 @@ static void test_boot_id_one(void (*setup)(void), size_t n_boots_expected) {
for (int i = - (int) n_boots + 1; i <= (int) n_boots; i++) {
sd_id128_t id;
assert_ret(sd_journal_open_directory(&j, t, 0));
assert_ret(sd_journal_open_directory(&j, t, SD_JOURNAL_ASSUME_IMMUTABLE));
assert_se(journal_find_boot_by_offset(j, i, &id) == 1);
if (i <= 0)
assert_se(sd_id128_equal(id, boots[n_boots + i - 1].id));
@@ -16,7 +16,7 @@ int main(int argc, char *argv[]) {
test_setup_logging(LOG_DEBUG);
assert_se(sd_journal_open(&j, 0) >= 0);
assert_se(sd_journal_open(&j, SD_JOURNAL_ASSUME_IMMUTABLE) >= 0);
assert_se(sd_journal_add_match(j, "foobar", 0) < 0);
assert_se(sd_journal_add_match(j, "foobar=waldo", 0) < 0);
@@ -119,7 +119,7 @@ static void run_test(void) {
(void) journal_file_offline_close(two);
(void) journal_file_offline_close(three);
assert_se(sd_journal_open_directory(&j, t, 0) >= 0);
assert_se(sd_journal_open_directory(&j, t, SD_JOURNAL_ASSUME_IMMUTABLE) >= 0);
assert_se(sd_journal_add_match(j, "MAGIC=quux", 0) >= 0);
SD_JOURNAL_FOREACH_BACKWARDS(j) {