]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mountfsd: improve logging
authorLennart Poettering <lennart@poettering.net>
Fri, 28 Nov 2025 15:22:21 +0000 (16:22 +0100)
committerLennart Poettering <lennart@poettering.net>
Sat, 24 Jan 2026 12:18:15 +0000 (13:18 +0100)
src/mountfsd/mountwork.c

index 242516619f956c4981984ec6e48e1922a4b950cb..7fbcb2247e0f89685f4c910a1ef3b94c534514d3 100644 (file)
@@ -779,6 +779,7 @@ static JSON_DISPATCH_ENUM_DEFINE(dispatch_mount_directory_mode, MountMapMode, mo
 
 static DirectoryOwnership validate_directory_fd(
                 int fd,
+                const char *path, /* purely for logging purposes */
                 uid_t peer_uid,
                 uid_t *ret_current_owner_uid) {
 
@@ -813,14 +814,14 @@ static DirectoryOwnership validate_directory_fd(
         if (st.st_uid == 0) {
                 *ret_current_owner_uid = st.st_uid;
                 if (peer_uid == 0) {
-                        log_debug("Directory file descriptor points to root owned directory, who is also the peer.");
+                        log_debug("Directory file descriptor points to root owned directory (%s), who is also the peer.", strna(path));
                         return DIRECTORY_IS_ROOT_PEER_OWNED;
                 }
-                log_debug("Directory file descriptor points to root owned directory.");
+                log_debug("Directory file descriptor points to root owned directory (%s).", strna(path));
                 return DIRECTORY_IS_ROOT_OWNED;
         }
         if (st.st_uid == peer_uid) {
-                log_debug("Directory file descriptor points to peer owned directory.");
+                log_debug("Directory file descriptor points to peer owned directory (%s).", strna(path));
                 *ret_current_owner_uid = st.st_uid;
                 return DIRECTORY_IS_PEER_OWNED;
         }
@@ -841,7 +842,7 @@ static DirectoryOwnership validate_directory_fd(
 
                 /* If the peer is root, then it doesn't matter if we find a parent owned by root, let's shortcut things. */
                 if (peer_uid == 0) {
-                        log_debug("Directory file descriptor is owned by foreign UID range, and peer is root.");
+                        log_debug("Directory referenced by file descriptor is owned by foreign UID range, and peer is root.");
                         *ret_current_owner_uid = st.st_uid;
                         return DIRECTORY_IS_FOREIGN_OWNED;
                 }
@@ -924,8 +925,12 @@ static int vl_method_mount_directory(
         if (r < 0)
                 return log_debug_errno(r, "Failed to get client UID: %m");
 
+        /* Get path of the fd, to improve logging */
+        _cleanup_free_ char *directory_path = NULL;
+        (void) fd_get_path(directory_fd, &directory_path);
+
         uid_t current_owner_uid;
-        DirectoryOwnership owned_by = validate_directory_fd(directory_fd, peer_uid, &current_owner_uid);
+        DirectoryOwnership owned_by = validate_directory_fd(directory_fd, directory_path, peer_uid, &current_owner_uid);
         if (owned_by == -EREMOTEIO)
                 return sd_varlink_errorbo(link, "io.systemd.MountFileSystem.BadFileDescriptorFlags", SD_JSON_BUILD_PAIR_STRING("parameter", "directoryFileDescriptor"));
         if (owned_by < 0)
@@ -941,9 +946,6 @@ static int vl_method_mount_directory(
                 assert(p.mode > 0);
         }
 
-        _cleanup_free_ char *directory_path = NULL;
-        (void) fd_get_path(directory_fd, &directory_path);
-
         log_debug("Mounting '%s' with mapping mode: %s", strna(directory_path), mount_map_mode_to_string(p.mode));
 
         const char *polkit_details[] = {