Skip to content

Commit

Permalink
init: improve nvidia symlinks resolution. Fix #1668
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Di Maio <[email protected]>
  • Loading branch information
89luca89 committed Jan 25, 2025
1 parent b7cc703 commit 39f5f29
Showing 1 changed file with 3 additions and 22 deletions.
25 changes: 3 additions & 22 deletions distrobox-init
Original file line number Diff line number Diff line change
Expand Up @@ -323,25 +323,6 @@ init_readlink()
ls -l "${1}" | grep -Eo '\->.*' | cut -d' ' -f2- | sed 's|\.\./|/|g'
}

# init_readlink_rec will recursively resolve links
# Arguments:
# source file
# Expected env variables:
# None
# Expected global variables:
# None
# Outputs:
# original path the link is pointing
init_readlink_rec()
{
# shellcheck disable=SC2010
resolved="$(ls -l "${1}" | grep -Eo '\->.*' | cut -d' ' -f2- | sed 's|\.\./|/|g')"
if [ -L "${resolved}" ]; then
resolved="$(init_readlink_rec "${resolved}")"
fi
echo "${resolved}"
}

# mount_bind will perform a bind mount for inputs or error
# Arguments:
# source_dir: string what to mount
Expand Down Expand Up @@ -1895,7 +1876,7 @@ if [ "${nvidia}" -eq 1 ]; then
fi

if [ "${type}" = "link" ]; then
nvidia_file="/run/host/$(init_readlink_rec "${nvidia_file}")"
nvidia_file="$(readlink -fm "${nvidia_file}")"
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.
Expand Down Expand Up @@ -1963,7 +1944,7 @@ if [ "${nvidia}" -eq 1 ]; then
fi

if [ "${type}" = "link" ]; then
nvidia_file="/run/host/$(init_readlink_rec "${nvidia_file}")"
nvidia_file="$(readlink -fm "${nvidia_file}")"
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.
Expand Down Expand Up @@ -2029,7 +2010,7 @@ if [ "${nvidia}" -eq 1 ]; then
fi

if [ "${type}" = "link" ]; then
nvidia_lib="/run/host/$(init_readlink_rec "${nvidia_lib}")"
nvidia_lib="$(readlink -fm "${nvidia_lib}")"
fi

# Mounting read-only in a user namespace will trigger a check to see if certain
Expand Down

0 comments on commit 39f5f29

Please sign in to comment.