Minor follow-ups for recent PRs (#43148)

This commit is contained in:
Yu Watanabe
2026-07-25 21:08:37 +09:00
committed by GitHub
7 changed files with 23 additions and 25 deletions
-7
View File
@@ -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);
}
+6 -1
View File
@@ -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) {
+5 -4
View File
@@ -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;
+1 -2
View File
@@ -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);
+1 -1
View File
@@ -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)
+9 -9
View File
@@ -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));
+1 -1
View File
@@ -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)