From 171ddae1a122e9c97b4ef12ccb2d29e1ba7a318a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 1 Mar 2024 14:46:27 +0100 Subject: [PATCH] hostnamed: add explicit BUS_ERROR_NO_HARDWARE_SERIAL error For the very similar case of the product UUID we have its own error BUS_ERROR_NO_PRODUCT_UUID if we have no UUID. Let's mirror this for the hardware serial, and expose the same, to keep things nicely symmteric. --- src/hostname/hostnamed.c | 3 ++- src/libsystemd/sd-bus/bus-common-errors.c | 1 + src/libsystemd/sd-bus/bus-common-errors.h | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index 87662e2091..e5679ab931 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c @@ -1365,7 +1365,8 @@ static int method_get_hardware_serial(sd_bus_message *m, void *userdata, sd_bus_ r = get_hardware_serial(&serial); if (r < 0) - return r; + return sd_bus_error_set(error, BUS_ERROR_NO_HARDWARE_SERIAL, + "Failed to read hardware serial from firmware."); r = sd_bus_message_new_method_return(m, &reply); if (r < 0) diff --git a/src/libsystemd/sd-bus/bus-common-errors.c b/src/libsystemd/sd-bus/bus-common-errors.c index e44795b1d3..de12ec5e9e 100644 --- a/src/libsystemd/sd-bus/bus-common-errors.c +++ b/src/libsystemd/sd-bus/bus-common-errors.c @@ -105,6 +105,7 @@ BUS_ERROR_MAP_ELF_REGISTER const sd_bus_error_map bus_common_errors[] = { SD_BUS_ERROR_MAP(BUS_ERROR_TRANSFER_IN_PROGRESS, EBUSY), SD_BUS_ERROR_MAP(BUS_ERROR_NO_PRODUCT_UUID, EOPNOTSUPP), + SD_BUS_ERROR_MAP(BUS_ERROR_NO_HARDWARE_SERIAL, EOPNOTSUPP), SD_BUS_ERROR_MAP(BUS_ERROR_FILE_IS_PROTECTED, EACCES), SD_BUS_ERROR_MAP(BUS_ERROR_READ_ONLY_FILESYSTEM, EROFS), diff --git a/src/libsystemd/sd-bus/bus-common-errors.h b/src/libsystemd/sd-bus/bus-common-errors.h index 36f53dbde1..94dc85d301 100644 --- a/src/libsystemd/sd-bus/bus-common-errors.h +++ b/src/libsystemd/sd-bus/bus-common-errors.h @@ -106,6 +106,7 @@ #define BUS_ERROR_TRANSFER_IN_PROGRESS "org.freedesktop.import1.TransferInProgress" #define BUS_ERROR_NO_PRODUCT_UUID "org.freedesktop.hostname1.NoProductUUID" +#define BUS_ERROR_NO_HARDWARE_SERIAL "org.freedesktop.hostname1.NoHardwareSerial" #define BUS_ERROR_FILE_IS_PROTECTED "org.freedesktop.hostname1.FileIsProtected" #define BUS_ERROR_READ_ONLY_FILESYSTEM "org.freedesktop.hostname1.ReadOnlyFilesystem"