systemd/SOURCES/0773-test-id128-simplify-machine-id-check.patch

49 lines
2.2 KiB
Diff

From b54eb7dbdad4135fdcf846f6087ca29b6164b60b Mon Sep 17 00:00:00 2001
From: Frantisek Sumsal <frantisek@sumsal.cz>
Date: Tue, 27 Feb 2024 16:03:10 +0100
Subject: [PATCH] test-id128: simplify machine-id check
This also ensures that the test is skipped when /etc/machine-id exists,
but is not initialized.
(cherry picked from commit 415eb50570744daf2257fc6fc96e2d5750532785)
Related: RHEL-27512
---
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);