]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: move debug logging from _can_live_mount() functions to caller 34791/head
authorLennart Poettering <lennart@poettering.net>
Wed, 16 Oct 2024 08:45:10 +0000 (10:45 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 16 Oct 2024 08:50:15 +0000 (10:50 +0200)
Let's debug log the returned dbus error where we want the logging, but
don't log it, where we don't.

This removes the noisy logging from the property handler for the
CanLiveMount property, but keeps it in place for the MountImage() method
call where we want it.

Alternative to #34175

Follow-up for 5162829ec87df20c7af763bdf274735bf9e53552 and 1cafbecabecc619b4e147abd9925282d0ff323bd

src/core/dbus-service.c
src/core/service.c
src/core/unit.c

index 77e9a08bdd279ff36744f49fade5edda435c4b4b..85eb99f218eca1dc6107ac02409fe684a88dc951 100644 (file)
@@ -168,7 +168,7 @@ static int bus_service_method_mount(sd_bus_message *message, void *userdata, sd_
 
         r = unit_can_live_mount(u, error);
         if (r < 0)
-                return r;
+                return log_unit_debug_errno(u, r, "Cannot schedule live mount operation: %s", bus_error_message(error, r));
 
         r = mac_selinux_unit_access_check(u, message, "start", error);
         if (r < 0)
index eef9448edd1388a61d8d7071480aa56edbed5381..dfad574e65969a6229aa4b5f5c5a38e7ed81f5ce 100644 (file)
@@ -5309,18 +5309,12 @@ static int service_can_live_mount(const Unit *u, sd_bus_error *error) {
         assert(u);
 
         /* Ensure that the unit runs in a private mount namespace */
-        if (!exec_needs_mount_namespace(unit_get_exec_context(u), /* params= */ NULL, unit_get_exec_runtime(u))) {
-
-                /* This is also called in property_get_can_live_mount(). Suppress the debugging log when called in it. */
-                if (error)
-                        log_unit_debug(u, "Unit not running in private mount namespace, cannot live mount");
-
+        if (!exec_needs_mount_namespace(unit_get_exec_context(u), /* params= */ NULL, unit_get_exec_runtime(u)))
                 return sd_bus_error_setf(
                                 error,
                                 SD_BUS_ERROR_INVALID_ARGS,
-                                "Live mounting for unit '%s' cannot be scheduled: unit not running in private mount namespace",
+                                "Unit '%s' not running in private mount namespace, cannot live mount.",
                                 u->id);
-        }
 
         return 0;
 }
index 684fe698eea39db39eda3f9c7934dd36b9597e43..4384e3bfcbf2830a3c4c2fc7e83c80d36baf32af 100644 (file)
@@ -6396,24 +6396,20 @@ Condition *unit_find_failed_condition(Unit *u) {
 int unit_can_live_mount(const Unit *u, sd_bus_error *error) {
         assert(u);
 
-        if (!UNIT_VTABLE(u)->live_mount) {
-                log_unit_debug(u, "Live mounting not supported for unit type '%s'", unit_type_to_string(u->type));
+        if (!UNIT_VTABLE(u)->live_mount)
                 return sd_bus_error_setf(
                                 error,
                                 SD_BUS_ERROR_INVALID_ARGS,
-                                "Live mounting for unit '%s' cannot be scheduled: live mounting not supported for unit type '%s'",
-                                u->id,
-                                unit_type_to_string(u->type));
-        }
+                                "Live mounting not supported for unit type '%s' of unit '%s'.",
+                                unit_type_to_string(u->type),
+                                u->id);
 
-        if (u->load_state != UNIT_LOADED) {
-                log_unit_debug(u, "Unit not loaded");
+        if (u->load_state != UNIT_LOADED)
                 return sd_bus_error_setf(
                                 error,
                                 BUS_ERROR_NO_SUCH_UNIT,
-                                "Live mounting for unit '%s' cannot be scheduled: unit not loaded",
+                                "Unit '%s' not loaded, cannot live mount.",
                                 u->id);
-        }
 
         if (!UNIT_VTABLE(u)->can_live_mount)
                 return 0;