#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;
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)
#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"
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)
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)) {
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;
}
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);