From aa2e664e1861e8874c8ead61419d1ea057b92ceb Mon Sep 17 00:00:00 2001 From: Adrian Vovk Date: Fri, 30 Aug 2024 21:43:44 -0400 Subject: [PATCH] sysupdated: Register known error types This fixes a bug introduced during review of sysupdated. Originally, we just returned EALREADY verbatim to signify that the target is already up-to-date. Then we switched this to a proper error (org.freedesktop.sysupdate1.NoCandidate) during review. But that now maps to EIO, not EALREADY. Thus, whenever there's nothing to update, updatectl would report I/O errors to the user, even though nothing actually went wrong. --- src/libsystemd/sd-bus/bus-common-errors.c | 2 ++ src/libsystemd/sd-bus/bus-common-errors.h | 2 ++ src/sysupdate/sysupdated.c | 5 +++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libsystemd/sd-bus/bus-common-errors.c b/src/libsystemd/sd-bus/bus-common-errors.c index 5b18241f00e..db1285e7f0f 100644 --- a/src/libsystemd/sd-bus/bus-common-errors.c +++ b/src/libsystemd/sd-bus/bus-common-errors.c @@ -153,5 +153,7 @@ BUS_ERROR_MAP_ELF_REGISTER const sd_bus_error_map bus_common_errors[] = { SD_BUS_ERROR_MAP(BUS_ERROR_REBALANCE_NOT_NEEDED, EALREADY), SD_BUS_ERROR_MAP(BUS_ERROR_HOME_NOT_REFERENCED, EBADR), + SD_BUS_ERROR_MAP(BUS_ERROR_NO_UPDATE_CANDIDATE, EALREADY), + SD_BUS_ERROR_MAP_END }; diff --git a/src/libsystemd/sd-bus/bus-common-errors.h b/src/libsystemd/sd-bus/bus-common-errors.h index fb1d4211681..622cf4933db 100644 --- a/src/libsystemd/sd-bus/bus-common-errors.h +++ b/src/libsystemd/sd-bus/bus-common-errors.h @@ -158,4 +158,6 @@ #define BUS_ERROR_REBALANCE_NOT_NEEDED "org.freedesktop.home1.RebalanceNotNeeded" #define BUS_ERROR_HOME_NOT_REFERENCED "org.freedesktop.home1.HomeNotReferenced" +#define BUS_ERROR_NO_UPDATE_CANDIDATE "org.freedesktop.sysupdate1.NoCandidate" + BUS_ERROR_MAP_ELF_USE(bus_common_errors); diff --git a/src/sysupdate/sysupdated.c b/src/sysupdate/sysupdated.c index 4edfea937e1..9a078aa84a2 100644 --- a/src/sysupdate/sysupdated.c +++ b/src/sysupdate/sysupdated.c @@ -4,6 +4,7 @@ #include "sd-json.h" #include "build-path.h" +#include "bus-common-errors.h" #include "bus-error.h" #include "bus-get-properties.h" #include "bus-label.h" @@ -1044,8 +1045,8 @@ static int target_method_update_finished_early( /* Called when job finishes w/ a successful exit code, but before any work begins. * This happens when there is no candidate (i.e. we're already up-to-date), or * specified update is already installed. */ - return sd_bus_error_setf(error, "org.freedesktop.sysupdate1.NoCandidate", - "Job exited successfully with no work to do, assume already updated"); + return sd_bus_error_setf(error, BUS_ERROR_NO_UPDATE_CANDIDATE, + "Job exited successfully with no work to do, assume already updated"); } static int target_method_update_detach(sd_bus_message *msg, const Job *j) { -- 2.47.3