From: Lennart Poettering Date: Fri, 28 Nov 2025 15:22:21 +0000 (+0100) Subject: mountfsd: improve logging X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c5761f352ba473ba7777379d67959b63b10a9084;p=thirdparty%2Fsystemd.git mountfsd: improve logging --- diff --git a/src/mountfsd/mountwork.c b/src/mountfsd/mountwork.c index 242516619f9..7fbcb2247e0 100644 --- a/src/mountfsd/mountwork.c +++ b/src/mountfsd/mountwork.c @@ -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, ¤t_owner_uid); + DirectoryOwnership owned_by = validate_directory_fd(directory_fd, directory_path, peer_uid, ¤t_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[] = {