From 415eb50570744daf2257fc6fc96e2d5750532785 Mon Sep 17 00:00:00 2001 From: Nick Rosbrook Date: Mon, 12 Dec 2022 14:35:08 -0500 Subject: [PATCH 1/5] test-id128: simplify machine-id check This also ensures that the test is skipped when /etc/machine-id exists, but is not initialized. --- src/test/test-id128.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/test-id128.c b/src/test/test-id128.c index b7a9b03403..afdbf1e4b9 100644 --- a/src/test/test-id128.c +++ b/src/test/test-id128.c @@ -38,7 +38,7 @@ TEST(id128) { assert_se(!sd_id128_in_set(id, ID128_WALDI)); assert_se(!sd_id128_in_set(id, ID128_WALDI, ID128_WALDI)); - if (sd_booted() > 0 && access("/etc/machine-id", F_OK) >= 0) { + if (sd_booted() > 0 && sd_id128_get_machine(NULL) >= 0) { assert_se(sd_id128_get_machine(&id) == 0); printf("machine: %s\n", sd_id128_to_string(id, t)); @@ -170,7 +170,7 @@ TEST(id128) { assert_se(lseek(fd, 0, SEEK_SET) == 0); assert_se(id128_read_fd(fd, ID128_FORMAT_ANY, NULL) == -EUCLEAN); - if (sd_booted() > 0 && access("/etc/machine-id", F_OK) >= 0) { + if (sd_booted() > 0 && sd_id128_get_machine(NULL) >= 0) { assert_se(sd_id128_get_machine_app_specific(SD_ID128_MAKE(f0,3d,aa,eb,1c,33,4b,43,a7,32,17,29,44,bf,77,2e), &id) >= 0); assert_se(sd_id128_get_machine_app_specific(SD_ID128_MAKE(f0,3d,aa,eb,1c,33,4b,43,a7,32,17,29,44,bf,77,2e), &id2) >= 0); assert_se(sd_id128_equal(id, id2)); @@ -195,8 +195,8 @@ TEST(benchmark_sd_id128_get_machine_app_specific) { unsigned iterations = slow_tests_enabled() ? 1000000 : 1000; usec_t t, q; - if (access("/etc/machine-id", F_OK) < 0 && errno == ENOENT) - return (void) log_tests_skipped("/etc/machine-id does not exist"); + if (sd_id128_get_machine(NULL) < 0) + return (void) log_tests_skipped("/etc/machine-id is not initialized"); log_info("/* %s (%u iterations) */", __func__, iterations); From 079fcdd04f57bfb1e333fea853e050c99eb16e02 Mon Sep 17 00:00:00 2001 From: Nick Rosbrook Date: Mon, 12 Dec 2022 14:37:52 -0500 Subject: [PATCH 2/5] test-fs-util: skip part of test_chase_symlinks if machine-id is not initialized The part of test_chase_symlink in test-fs-util that calls sd_id128_get_machine will fail if /etc/machine-id is empty, so skip this block if the machine-id is not initialized. --- src/test/test-fs-util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c index 16c6774a65..69f6303990 100644 --- a/src/test/test-fs-util.c +++ b/src/test/test-fs-util.c @@ -315,7 +315,7 @@ TEST(chase_symlinks) { assert_se(symlink("/usr/../etc/./machine-id", p) >= 0); r = chase_symlinks(p, NULL, 0, NULL, &pfd); - if (r != -ENOENT) { + if (r != -ENOENT && sd_id128_get_machine(NULL) >= 0) { _cleanup_close_ int fd = -1; sd_id128_t a, b; From a635b6279cf35abad3abe169780ec899df9396df Mon Sep 17 00:00:00 2001 From: Nick Rosbrook Date: Tue, 13 Dec 2022 12:22:37 -0500 Subject: [PATCH 3/5] test-unit-name: simplify machine-id check --- src/test/test-unit-name.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/test-unit-name.c b/src/test/test-unit-name.c index 98fffc7c87..c6428e844f 100644 --- a/src/test/test-unit-name.c +++ b/src/test/test-unit-name.c @@ -3,6 +3,8 @@ #include #include +#include "sd-id128.h" + #include "alloc-util.h" #include "all-units.h" #include "glob-util.h" @@ -261,7 +263,7 @@ TEST_RET(unit_printf, .sd_booted = true) { assert_se(short_hostname); assert_se(specifier_pretty_hostname('q', NULL, NULL, NULL, &pretty_hostname) == 0); assert_se(pretty_hostname); - if (access("/etc/machine-id", F_OK) >= 0) { + if (sd_id128_get_machine(NULL) >= 0) { assert_se(specifier_machine_id('m', NULL, NULL, NULL, &machine_id) >= 0); assert_se(machine_id); } From 2c6b738badf1404b3ceb7e322eeeb736b57f6162 Mon Sep 17 00:00:00 2001 From: Nick Rosbrook Date: Tue, 13 Dec 2022 12:25:35 -0500 Subject: [PATCH 4/5] test-load-fragment: simplify machine-id check --- src/test/test-load-fragment.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/test-load-fragment.c b/src/test/test-load-fragment.c index 3cf704134c..997c2b2524 100644 --- a/src/test/test-load-fragment.c +++ b/src/test/test-load-fragment.c @@ -5,6 +5,8 @@ #include #include +#include "sd-id128.h" + #include "all-units.h" #include "alloc-util.h" #include "capability-util.h" @@ -518,7 +520,7 @@ TEST(install_printf, .sd_booted = true) { _cleanup_free_ char *mid = NULL, *bid = NULL, *host = NULL, *gid = NULL, *group = NULL, *uid = NULL, *user = NULL; - if (access("/etc/machine-id", F_OK) >= 0) + if (sd_id128_get_machine(NULL) >= 0) assert_se(specifier_machine_id('m', NULL, NULL, NULL, &mid) >= 0 && mid); if (sd_booted() > 0) assert_se(specifier_boot_id('b', NULL, NULL, NULL, &bid) >= 0 && bid); From 3a9ca230363e6d1063a789492005d744723f5eed Mon Sep 17 00:00:00 2001 From: Nick Rosbrook Date: Wed, 14 Dec 2022 10:07:40 -0500 Subject: [PATCH 5/5] journal: skip part of test-journal-interleaving if no machine-id exists When executed on a systemd with an empty /etc/machine-id, test-journal-interleaving fails in test_sequence_numbers_one() when re-opening the existing "two.journal". This is because opening the existing journal file with managed_journal_file_open() causes journal_file_verify_header() to be called. This function tries to compare the current machine-id to the machine-id in the journal file header, but does not handle the case where the machine-id is empty or non-existent. Check if we have an initialized machine-id before executing this portion of the test. --- src/journal/test-journal-interleaving.c | 27 +++++++++++++++---------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/journal/test-journal-interleaving.c b/src/journal/test-journal-interleaving.c index 7939574c37..379a0c8caf 100644 --- a/src/journal/test-journal-interleaving.c +++ b/src/journal/test-journal-interleaving.c @@ -3,6 +3,7 @@ #include #include +#include "sd-id128.h" #include "sd-journal.h" #include "alloc-util.h" @@ -262,22 +263,26 @@ static void test_sequence_numbers_one(void) { test_close(one); - /* restart server */ - seqnum = 0; + /* If the machine-id is not initialized, the header file verification + * (which happens when re-opening a journal file) will fail. */ + if (sd_id128_get_machine(NULL) >= 0) { + /* restart server */ + seqnum = 0; - assert_se(managed_journal_file_open(-1, "two.journal", O_RDWR, JOURNAL_COMPRESS, 0, - UINT64_MAX, NULL, m, NULL, NULL, &two) == 0); + assert_se(managed_journal_file_open(-1, "two.journal", O_RDWR, JOURNAL_COMPRESS, 0, + UINT64_MAX, NULL, m, NULL, NULL, &two) == 0); - assert_se(sd_id128_equal(two->file->header->seqnum_id, seqnum_id)); + assert_se(sd_id128_equal(two->file->header->seqnum_id, seqnum_id)); - append_number(two, 7, &seqnum); - printf("seqnum=%"PRIu64"\n", seqnum); - assert_se(seqnum == 5); + append_number(two, 7, &seqnum); + printf("seqnum=%"PRIu64"\n", seqnum); + assert_se(seqnum == 5); - /* So..., here we have the same seqnum in two files with the - * same seqnum_id. */ + /* So..., here we have the same seqnum in two files with the + * same seqnum_id. */ - test_close(two); + test_close(two); + } log_info("Done...");