sd-id128: introduce ERRNO_IS_NEG_MACHINE_ID_UNSET

This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2023-08-16 12:52:56 +02:00
parent 3c8c67ce1d
commit d66ad6ff85
4 changed files with 14 additions and 15 deletions
+3 -5
View File
@@ -27,12 +27,10 @@ static int load_etc_machine_id(void) {
int r;
r = sd_id128_get_machine(&arg_machine_id);
if (r < 0) {
if (ERRNO_IS_MACHINE_ID_UNSET(r)) /* Not set or empty */
return 0;
if (ERRNO_IS_NEG_MACHINE_ID_UNSET(r)) /* Not set or empty */
return 0;
if (r < 0)
return log_error_errno(r, "Failed to get machine-id: %m");
}
log_debug("Loaded machine ID %s from /etc/machine-id.", SD_ID128_TO_STRING(arg_machine_id));
return 0;
+3 -4
View File
@@ -448,11 +448,10 @@ static int context_load_machine_id(Context *c) {
assert(c);
r = id128_get_machine_at(c->rfd, &c->machine_id);
if (r < 0) {
if (ERRNO_IS_MACHINE_ID_UNSET(r))
return 0;
if (ERRNO_IS_NEG_MACHINE_ID_UNSET(r))
return 0;
if (r < 0)
return log_error_errno(r, "Failed to load machine ID from /etc/machine-id: %m");
}
log_debug("MACHINE_ID=%s set via /etc/machine-id.", SD_ID128_TO_STRING(c->machine_id));
return 1; /* loaded */
+7 -5
View File
@@ -6,6 +6,7 @@
#include "sd-id128.h"
#include "errno-util.h"
#include "hash-funcs.h"
#include "macro.h"
@@ -45,8 +46,9 @@ sd_id128_t id128_make_v4_uuid(sd_id128_t id);
int id128_get_product(sd_id128_t *ret);
/* A helper to check for the three relevant cases of "machine ID not initialized" */
#define ERRNO_IS_MACHINE_ID_UNSET(r) \
IN_SET(abs(r), \
ENOENT, \
ENOMEDIUM, \
ENOPKG)
#define ERRNO_IS_NEG_MACHINE_ID_UNSET(r) \
IN_SET(r, \
-ENOENT, \
-ENOMEDIUM, \
-ENOPKG)
_DEFINE_ABS_WRAPPER(MACHINE_ID_UNSET);
+1 -1
View File
@@ -251,7 +251,7 @@ TEST(condition_test_host) {
int r;
r = sd_id128_get_machine(&id);
if (r < 0 && ERRNO_IS_MACHINE_ID_UNSET(r))
if (ERRNO_IS_NEG_MACHINE_ID_UNSET(r))
return (void) log_tests_skipped("/etc/machine-id missing");
assert_se(r >= 0);