diff --git a/src/imds/imds-generator.c b/src/imds/imds-generator.c index 08175df3e5..d79b3c341d 100644 --- a/src/imds/imds-generator.c +++ b/src/imds/imds-generator.c @@ -126,6 +126,26 @@ static int smbios_query(void) { return false; } +static int add_dmi_id_dependency(const char *dest, const char *unit) { + int r; + + /* We now know the SMBIOS device exists, hence it's safe now to order the IMDS service after it, so + * that it has all properties properly initialized. */ + + r = write_drop_in( + dest, + unit, + 50, "dmi-id", + "# Automatically generated by systemd-imds-generator\n\n" + "[Unit]\n" + "Wants=sys-devices-virtual-dmi-id.device\n" + "After=sys-devices-virtual-dmi-id.device\n"); + if (r < 0) + return log_error_errno(r, "Failed to hook DMI id device before %s: %m", unit); + + return 0; +} + static int run(const char *dest, const char *dest_early, const char *dest_late) { int r; @@ -161,6 +181,10 @@ static int run(const char *dest, const char *dest_early, const char *dest_late) r = generator_add_symlink(dest_early, SPECIAL_SYSINIT_TARGET, "wants", SYSTEM_DATA_UNIT_DIR "/systemd-imds-early-network.service"); if (r < 0) return log_error_errno(r, "Failed to hook in systemd-imds-early-network.service: %m"); + + r = add_dmi_id_dependency(dest_early, "systemd-imds-early-network.service"); + if (r < 0) + return r; } /* Enable the IMDS service socket */ @@ -168,18 +192,9 @@ static int run(const char *dest, const char *dest_early, const char *dest_late) if (r < 0) return log_error_errno(r, "Failed to hook in systemd-imdsd.socket: %m"); - /* We now know the SMBIOS device exists, hence it's safe now to order the IMDS service after it, so - * that it has all properties properly initialized. */ - r = write_drop_in( - dest_early, - "systemd-imdsd@.service", - 50, "dmi-id", - "# Automatically generated by systemd-imds-generator\n\n" - "[Unit]\n" - "Wants=sys-devices-virtual-dmi-id.device\n" - "After=sys-devices-virtual-dmi-id.device\n"); + r = add_dmi_id_dependency(dest_early, "systemd-imdsd@.service"); if (r < 0) - return log_error_errno(r, "Failed to hook DMI id device before systemd-imdsd@.service: %m"); + return r; if (arg_import < 0) arg_import = in_initrd();