mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 07:48:45 +00:00
[TUI] launcher: start the bundled runtime when access(X_OK) is denied (Fix #4309)
Rebased onto current main so the patch applies to today's files.
This commit is contained in:
1 parent
13eedf5524
commit
4be7c731e0
2 files changed
+31
-4
No files matched your search
Executable → Regular
+17
-3
@@ -28,9 +28,23 @@ while [ -L "$self" ]; do
|
||||
done
|
||||
HERE=$(CDPATH= cd -- "$(dirname -- "$self")" && pwd -P)
|
||||
|
||||
# Is this a Python this launcher can start?
|
||||
#
|
||||
# `test -x` alone is not a reliable yes/no. A container runtime's seccomp profile can deny
|
||||
# access(X_OK) and make it answer false for a file the shell can still execute. Measured in the
|
||||
# official image (0.2.2-cuda13) on Docker 19.03.15 with its default profile: `[ -x .../python3 ]`
|
||||
# is false, `[ -e .../python3 ]` is true, and the same path runs `python3 -V` normally. The
|
||||
# launcher then skipped the bundled runtime and printed "no usable Python found" with the runtime
|
||||
# present. So when the permission test says no, start the interpreter and let it decide.
|
||||
is_runnable() {
|
||||
[ -f "$1" ] || return 1 # a directory can be executable too, and it is never a Python
|
||||
[ -x "$1" ] && return 0 # the usual case, and the one a seccomp profile can answer wrongly
|
||||
"$1" -c 'pass' 2>/dev/null # access(X_OK) denied but the file is there: let the interpreter answer
|
||||
}
|
||||
|
||||
pick_python() {
|
||||
if [ -n "${STRATA_PYTHON:-}" ]; then
|
||||
if [ -x "$STRATA_PYTHON" ]; then printf '%s\n' "$STRATA_PYTHON"; return 0; fi
|
||||
if is_runnable "$STRATA_PYTHON"; then printf '%s\n' "$STRATA_PYTHON"; return 0; fi
|
||||
echo "strata: STRATA_PYTHON=$STRATA_PYTHON is not executable" >&2
|
||||
return 1
|
||||
fi
|
||||
@@ -45,7 +59,7 @@ pick_python() {
|
||||
for candidate in \
|
||||
"$HERE/../python/bin/python3" "$HERE/python/bin/python3" \
|
||||
"$HERE/../python/bin/python" "$HERE/python/bin/python"; do
|
||||
if [ -x "$candidate" ]; then printf '%s\n' "$candidate"; return 0; fi
|
||||
if is_runnable "$candidate"; then printf '%s\n' "$candidate"; return 0; fi
|
||||
done
|
||||
|
||||
# Anything on PATH that is new enough, then the usual places an interpreter lives on macOS
|
||||
@@ -64,7 +78,7 @@ pick_python() {
|
||||
/usr/bin/python3
|
||||
do
|
||||
[ -n "$candidate" ] || continue
|
||||
[ -x "$candidate" ] || continue
|
||||
is_runnable "$candidate" || continue
|
||||
if "$candidate" -c 'import sys; raise SystemExit(0 if sys.version_info[:2] >= (3, 10) else 1)' 2>/dev/null; then
|
||||
printf '%s\n' "$candidate"; return 0
|
||||
fi
|
||||
|
||||
Executable → Regular
+14
-1
@@ -27,7 +27,20 @@ set -u
|
||||
|
||||
APP=/opt/strata
|
||||
STRATA="$APP/terminal/bin/strata"
|
||||
PYBIN="$APP/terminal/python/bin/python3"; [ -x "$PYBIN" ] || PYBIN=$(command -v python3 || echo python3)
|
||||
|
||||
# Is this a Python this container can start? `test -x` alone is not a reliable yes/no: a container
|
||||
# runtime's seccomp profile can deny access(X_OK) and make it answer false for a file the shell can
|
||||
# still execute. Measured in this image on Docker 19.03.15's default profile: `[ -x .../python3 ]` is
|
||||
# false, `[ -e .../python3 ]` is true, and the same path runs `python3 -V` normally. The launcher in
|
||||
# bin/strata carries the same helper for the same reason (issue #4309).
|
||||
python_usable() {
|
||||
[ -f "$1" ] || return 1 # a directory can be executable too, and it is never a Python
|
||||
[ -x "$1" ] && return 0 # the usual case, and the one a seccomp profile can answer wrongly
|
||||
"$1" -c 'pass' 2>/dev/null # access(X_OK) denied but the file is there: let the interpreter answer
|
||||
}
|
||||
|
||||
PYBIN="$APP/terminal/python/bin/python3"
|
||||
python_usable "$PYBIN" || PYBIN=$(command -v python3 || echo python3)
|
||||
STATE_DIR="${XDG_STATE_HOME:-/data/state}/strata"
|
||||
KEY_FILE="${STRATA_KEY_FILE:-/data/state/api-key}"
|
||||
PHASE_FILE=/run/strata-phase
|
||||
|
||||
Reference in new issue
Block a user