From: Lennart Poettering Date: Thu, 20 Feb 2025 14:09:25 +0000 (+0100) Subject: homed: return the correct error if an image file is not present when we try to activa... X-Git-Tag: v258-rc1~1288 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2cf95e51784d897ce6e5be6a8e9cbeaba7b05c77;p=thirdparty%2Fsystemd.git homed: return the correct error if an image file is not present when we try to activate it We already return BUS_ERROR_HOME_ABSENT when we detect the image being absent before we fork off the homework worker. Let's also return the same error if the homework process notices the same condition while actually doing something. This mostly fixes a race, that the same condition seen at different points in time results in the same errors. --- diff --git a/src/home/homed-home.c b/src/home/homed-home.c index 96477b3061a..a2c28337f49 100644 --- a/src/home/homed-home.c +++ b/src/home/homed-home.c @@ -689,6 +689,8 @@ static int convert_worker_errno(Home *h, int e, sd_bus_error *error) { return sd_bus_error_setf(error, BUS_ERROR_HOME_CANT_AUTHENTICATE, "Home %s has no password or other authentication mechanism defined.", h->user_name); case -EADDRINUSE: return sd_bus_error_setf(error, BUS_ERROR_HOME_IN_USE, "Home %s is currently being used elsewhere.", h->user_name); + case -ENETUNREACH: + return sd_bus_error_setf(error, BUS_ERROR_HOME_ABSENT, "Backing storage for %s currently absent.", h->user_name); } return 0; diff --git a/src/home/homework.c b/src/home/homework.c index 00e74894b32..9d3eb94ab2b 100644 --- a/src/home/homework.c +++ b/src/home/homework.c @@ -926,7 +926,7 @@ static int home_activate(UserRecord *h, UserRecord **ret_home) { if (r < 0) return r; if (r == USER_TEST_ABSENT) - return log_error_errno(SYNTHETIC_ERRNO(ENOENT), "Image path %s is missing, refusing.", user_record_image_path(h)); + return log_error_errno(SYNTHETIC_ERRNO(ENETUNREACH), "Image path %s is missing, refusing.", user_record_image_path(h)); switch (user_record_storage(h)) { @@ -1596,7 +1596,7 @@ static int home_validate_update(UserRecord *h, HomeSetup *setup, HomeSetupFlags if (r < 0) return r; if (r == USER_TEST_ABSENT) - return log_error_errno(SYNTHETIC_ERRNO(ENOENT), "Image path %s does not exist", user_record_image_path(h)); + return log_error_errno(SYNTHETIC_ERRNO(ENETUNREACH), "Image path %s does not exist", user_record_image_path(h)); switch (user_record_storage(h)) { @@ -2092,6 +2092,7 @@ static int run(int argc, char *argv[]) { * ENOSPC → not enough disk space for operation * EKEYREVOKED → user record has not suitable hashed password or pkcs#11 entry, we cannot authenticate * EADDRINUSE → home image is already used elsewhere (lock taken) + * ENETUNREACH → backing storage is currently not (image is ENOENT, or AF_UNIX socket to connect to is ENOENT) */ if (streq(argv[1], "activate"))