From 236e2bfa88cf53c526bec97e13186084b0b36534 Mon Sep 17 00:00:00 2001 From: Luca Di Maio Date: Sun, 19 Jan 2025 15:23:11 +0100 Subject: [PATCH] init: improve nvidia integration, skip files when directory is already a ro-mountpoint, log with warnings Signed-off-by: Luca Di Maio --- distrobox-init | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/distrobox-init b/distrobox-init index 29303e7..66acd53 100755 --- a/distrobox-init +++ b/distrobox-init @@ -1887,6 +1887,10 @@ if [ "${nvidia}" -eq 1 ]; then for nvidia_file in ${NVIDIA_FILES}; do dest_file="$(printf "%s" "${nvidia_file}" | sed 's|/run/host||g')" + if [ ! -w "$(dirname "${dest_file}")" ]; then + printf "Warning: skpping file %s, %s mounted as read-only\n" "${dest_file}" "$(dirname "${dest_file}")" + continue + fi # Mounting read-only in a user namespace will trigger a check to see if certain # "locked" flags (line noexec,nodev,nosuid) are changed. This ensures we explicitly reuse those flags. locked_flags="$(get_locked_mount_flags "${nvidia_file}")" @@ -1908,6 +1912,10 @@ if [ "${nvidia}" -eq 1 ]; then for nvidia_file in ${NVIDIA_FILES}; do dest_file="$(printf "%s" "${nvidia_file}" | sed 's|/run/host||g')" + if [ ! -w "$(dirname "${dest_file}")" ]; then + printf "Warning: skpping file %s, %s mounted as read-only\n" "${dest_file}" "$(dirname "${dest_file}")" + continue + fi # Mounting read-only in a user namespace will trigger a check to see if certain # "locked" flags (line noexec,nodev,nosuid) are changed. This ensures we explicitly reuse those flags. locked_flags="$(get_locked_mount_flags "${nvidia_file}")" @@ -1969,6 +1977,11 @@ if [ "${nvidia}" -eq 1 ]; then continue fi + if [ ! -w "$(dirname "${dest_file}")" ]; then + printf "Warning: skpping file %s, %s mounted as read-only\n" "${dest_file}" "$(dirname "${dest_file}")" + continue + fi + type="file" if [ -L "${nvidia_lib}" ]; then type="link"