diff --git a/src/basic/alloc-util.c b/src/basic/alloc-util.c index 3a813575c3..04c4a50672 100644 --- a/src/basic/alloc-util.c +++ b/src/basic/alloc-util.c @@ -164,10 +164,3 @@ void* greedy_realloc_append( return q; } - -void free_many(void **p, size_t n) { - assert(p || n == 0); - - FOREACH_ARRAY(i, p, n) - *i = mfree(*i); -} diff --git a/src/basic/alloc-util.h b/src/basic/alloc-util.h index 1f0342eda3..8505205ce3 100644 --- a/src/basic/alloc-util.h +++ b/src/basic/alloc-util.h @@ -208,7 +208,12 @@ void* greedy_realloc_append(void **p, size_t *n_p, const void *from, size_t n_fr #endif /* Free every element of the array. */ -void free_many(void **p, size_t n); +static inline void free_many(void **p, size_t n) { + assert(p || n == 0); + + FOREACH_ARRAY(i, p, n) + *i = mfree(*i); +} /* Typesafe wrapper for char** rather than void**. Unfortunately C won't implicitly cast this. */ static inline void free_many_charp(char **c, size_t n) { diff --git a/src/imds/imds-generator.c b/src/imds/imds-generator.c index 3f22ca3031..08175df3e5 100644 --- a/src/imds/imds-generator.c +++ b/src/imds/imds-generator.c @@ -60,7 +60,7 @@ static int smbios_get_modalias(char **ret) { assert(ret); _cleanup_free_ char *modalias = NULL; - r = read_virtual_file("/sys/devices/virtual/dmi/id/modalias", SIZE_MAX, &modalias, /* ret_size= */ NULL); + r = read_full_virtual_file("/sys/devices/virtual/dmi/id/modalias", &modalias, /* ret_size= */ NULL); if (r < 0) return r; @@ -76,7 +76,7 @@ static int smbios_get_modalias(char **ret) { else { truncate_nl(cat); - if (!string_has_cc(cat, /* ok= */ NULL) && !isempty(cat) && !strextend(&modalias, "cat", cat, ":")) + if (!isempty(cat) && !string_has_cc(cat, /* ok= */ NULL) && !strextend(&modalias, "cat", cat, ":")) return -ENOMEM; } @@ -95,7 +95,7 @@ static int smbios_query(void) { _cleanup_free_ char *modalias = NULL; r = smbios_get_modalias(&modalias); if (r == -ENOENT) { - log_debug("No DMI device found, assuming IMDS is not available."); + log_debug_errno(r, "No DMI device found, assuming IMDS is not available."); return false; } if (r < 0) @@ -136,7 +136,7 @@ static int run(const char *dest, const char *dest_early, const char *dest_late) if (arg_enabled < 0) { Virtualization v = detect_container(); if (v < 0) - log_debug_errno(v, "Container detection failed, ignoring: %m"); + return log_error_errno(v, "Container detection failed: %m"); if (v > 0) { log_debug("Running in a container, disabling IMDS logic."); arg_enabled = false; @@ -148,6 +148,7 @@ static int run(const char *dest, const char *dest_early, const char *dest_late) } } + assert(arg_enabled >= 0); if (!arg_enabled) { log_debug("IMDS not enabled, skipping generator."); return 0; diff --git a/src/imds/imdsd.c b/src/imds/imdsd.c index 8d532ee655..aecc2feac7 100644 --- a/src/imds/imdsd.c +++ b/src/imds/imdsd.c @@ -127,8 +127,7 @@ static struct in6_addr arg_address_ipv6 = {}; static char *arg_well_known_key[_IMDS_WELL_KNOWN_MAX] = {}; static void imds_well_known_key_free(typeof(arg_well_known_key) *array) { - FOREACH_ARRAY(i, *array, _IMDS_WELL_KNOWN_MAX) - free(*i); + free_many_charp(*array, _IMDS_WELL_KNOWN_MAX); } STATIC_DESTRUCTOR_REGISTER(arg_ifname, freep); diff --git a/src/pcrlock/pcrlock.c b/src/pcrlock/pcrlock.c index ecb0bb30e6..33b35ac414 100644 --- a/src/pcrlock/pcrlock.c +++ b/src/pcrlock/pcrlock.c @@ -927,7 +927,7 @@ static int event_log_load_firmware(EventLog *el) { r = read_full_file(path, (char**) &buf, &bufsize); if (r == -ENOENT) { - log_notice("No '%s' file, assuming TPM without firmware support.", path); + log_notice_errno(r, "No '%s' file, assuming TPM without firmware support.", path); return 0; } if (r < 0) diff --git a/src/shared/efi-loader.c b/src/shared/efi-loader.c index 20e4719bb0..da0a3a57b5 100644 --- a/src/shared/efi-loader.c +++ b/src/shared/efi-loader.c @@ -281,13 +281,6 @@ int efi_measured_uki(int log_level) { * being used, but it measured things into a different PCR than we are configured for in * userspace. (i.e. we expect PCR 11 being used for this by both sd-stub and us) */ - r = secure_getenv_bool("SYSTEMD_FORCE_MEASURE"); /* Give user a chance to override the variable test, - * for debugging purposes */ - if (r >= 0) - return (cached = r); - if (r != -ENXIO) - log_debug_errno(r, "Failed to parse $SYSTEMD_FORCE_MEASURE, ignoring: %m"); - if (!efi_has_tpm2()) return (cached = 0); @@ -323,12 +316,19 @@ int efi_measured_os(int log_level) { if (cached >= 0) return cached; + r = secure_getenv_bool("SYSTEMD_FORCE_MEASURE"); /* Give user a chance to override the variable test, + * for debugging purposes */ + if (r >= 0) + return (cached = r); + if (r != -ENXIO) + log_debug_errno(r, "Failed to parse $SYSTEMD_FORCE_MEASURE, ignoring: %m"); + bool b; r = proc_cmdline_get_bool("systemd.tpm2_measured_os", /* flags= */ 0, &b); + if (r > 0) + return (cached = b); if (r < 0) log_debug_errno(r, "Failed to parse systemd.tpm2_measured_os= kernel command line argument, ignoring: %m"); - else if (r > 0) - return (cached = b); /* If nothing is explicitly configured, just assume that if we booted with a measured UKI we also want a measured OS */ return (cached = efi_measured_uki(log_level)); diff --git a/src/tpm2-setup/tpm2-generator.c b/src/tpm2-setup/tpm2-generator.c index 7a826a0be1..6c27fa106a 100644 --- a/src/tpm2-setup/tpm2-generator.c +++ b/src/tpm2-setup/tpm2-generator.c @@ -92,7 +92,7 @@ static int generate_swtpm_symlink(Tpm2Support support) { r = find_executable("swtpm", /* ret_filename= */ NULL); if (r == -ENOENT) { - log_warning("TPM software fallback requested but swtpm not available, not pulling in software TPM unit."); + log_warning_errno(r, "TPM software fallback requested but swtpm not available, not pulling in software TPM unit."); return 0; } if (r < 0)