mirror of
https://github.com/systemd/systemd.git
synced 2025-03-19 22:50:17 +03:00
id128: introduce ERRNO_IS_MACHINE_ID_UNSET() helper macro
This commit is contained in:
parent
19cfda9fc3
commit
74e795ee55
@ -6,30 +6,33 @@
|
||||
#include "bootctl-util.h"
|
||||
#include "chase-symlinks.h"
|
||||
#include "copy.h"
|
||||
#include "dirent-util.h"
|
||||
#include "efi-api.h"
|
||||
#include "env-file.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "fs-util.h"
|
||||
#include "glyph-util.h"
|
||||
#include "id128-util.h"
|
||||
#include "os-util.h"
|
||||
#include "path-util.h"
|
||||
#include "rm-rf.h"
|
||||
#include "stat-util.h"
|
||||
#include "sync-util.h"
|
||||
#include "tmpfile-util.h"
|
||||
#include "umask-util.h"
|
||||
#include "utf8.h"
|
||||
#include "dirent-util.h"
|
||||
#include "efi-api.h"
|
||||
#include "rm-rf.h"
|
||||
|
||||
static int load_etc_machine_id(void) {
|
||||
int r;
|
||||
|
||||
r = sd_id128_get_machine(&arg_machine_id);
|
||||
if (IN_SET(r, -ENOENT, -ENOMEDIUM, -ENOPKG)) /* Not set or empty */
|
||||
return 0;
|
||||
if (r < 0)
|
||||
if (r < 0) {
|
||||
if (ERRNO_IS_MACHINE_ID_UNSET(r)) /* Not set or empty */
|
||||
return 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;
|
||||
|
@ -32,3 +32,10 @@ extern const struct hash_ops id128_hash_ops_free;
|
||||
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)
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "fd-util.h"
|
||||
#include "format-util.h"
|
||||
#include "fs-util.h"
|
||||
#include "id128-util.h"
|
||||
#include "journal-authenticate.h"
|
||||
#include "journal-def.h"
|
||||
#include "journal-file.h"
|
||||
@ -388,11 +389,13 @@ static int journal_file_refresh_header(JournalFile *f) {
|
||||
assert(f->header);
|
||||
|
||||
r = sd_id128_get_machine(&f->header->machine_id);
|
||||
if (IN_SET(r, -ENOENT, -ENOMEDIUM, -ENOPKG))
|
||||
/* We don't have a machine-id, let's continue without */
|
||||
zero(f->header->machine_id);
|
||||
else if (r < 0)
|
||||
return r;
|
||||
if (r < 0) {
|
||||
if (!ERRNO_IS_MACHINE_ID_UNSET(r))
|
||||
return r;
|
||||
|
||||
/* don't have a machine-id, let's continue without */
|
||||
f->header->machine_id = SD_ID128_NULL;
|
||||
}
|
||||
|
||||
r = sd_id128_get_boot(&f->header->boot_id);
|
||||
if (r < 0)
|
||||
|
@ -2841,7 +2841,7 @@ static int setup_machine_id(const char *directory) {
|
||||
|
||||
r = id128_read(etc_machine_id, ID128_FORMAT_PLAIN, &id);
|
||||
if (r < 0) {
|
||||
if (!IN_SET(r, -ENOENT, -ENOMEDIUM, -ENOPKG)) /* If the file is missing, empty, or uninitialized, we don't mind */
|
||||
if (!ERRNO_IS_MACHINE_ID_UNSET(r)) /* If the file is missing, empty, or uninitialized, we don't mind */
|
||||
return log_error_errno(r, "Failed to read machine ID from container image: %m");
|
||||
|
||||
if (sd_id128_is_null(arg_uuid)) {
|
||||
|
@ -4789,10 +4789,12 @@ static int context_read_seed(Context *context, const char *root) {
|
||||
return log_error_errno(fd, "Failed to determine machine ID of image: %m");
|
||||
else {
|
||||
r = id128_read_fd(fd, ID128_FORMAT_PLAIN, &context->seed);
|
||||
if (IN_SET(r, -ENOMEDIUM, -ENOPKG))
|
||||
if (r < 0) {
|
||||
if (!ERRNO_IS_MACHINE_ID_UNSET(r))
|
||||
return log_error_errno(r, "Failed to parse machine ID of image: %m");
|
||||
|
||||
log_info("No machine ID set, using randomized partition UUIDs.");
|
||||
else if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse machine ID of image: %m");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -250,7 +250,7 @@ TEST(condition_test_host) {
|
||||
int r;
|
||||
|
||||
r = sd_id128_get_machine(&id);
|
||||
if (IN_SET(r, -ENOENT, -ENOMEDIUM, -ENOPKG))
|
||||
if (r < 0 && ERRNO_IS_MACHINE_ID_UNSET(r))
|
||||
return (void) log_tests_skipped("/etc/machine-id missing");
|
||||
assert_se(r >= 0);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user