Skip to content
Snippets Groups Projects
Commit d5932cb3 authored by Simon McVittie's avatar Simon McVittie
Browse files

_v2-entry-point: Remove support for running in "session mode"


We used to use this to process Windows games' installscripts, but since
Steam beta 1623823138, Steam implements a much simpler interface for
running installscripts and we don't need this any more. Less code means
fewer bugs! Instead of doing all the previous logic with commands run
in the background, we just call exec_container.

See also steam-runtime-tools!324, which documents the old and new
compatibility tool interfaces.

Resolves: T28961
Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
parent 1b730069
Branches
Tags
1 merge request!53Remove "session mode"
This commit is part of merge request !53. Comments created here will be created in the context of that merge request.
#!/usr/bin/env bash
set -eu
me="$(readlink -f "$0")"
here="${me%/*}"
me="${me##*/}"
# This is a prototype and will probably not survive in its current form.
# Don't rely on it.
force=
info=
rendezvous=
suite=
use_timestamp=
verbose=
if [ "${STEAM_LINUX_RUNTIME_VERBOSE-}" = 1 ]; then
verbose=yes
# Propagate it to pressure-vessel too
export PRESSURE_VESSEL_VERBOSE=1
fi
if [ "${STEAM_LINUX_RUNTIME_LOG-}" = 1 ]; then
# If we are logging to a file, use the timestamp
info=yes
use_timestamp=yes
fi
log () {
if [ -n "$use_timestamp" ]; then
printf '%s\n' "$(LD_PRELOAD='' date +'%H:%M:%S.%6N'): ${me}[$$]: $*" >&2
else
printf '%s\n' "${me}[$$]: $*" >&2
fi
}
info () {
if [ -n "${info}${verbose}" ]; then
log "$@"
fi
}
verbose () {
if [ -n "$verbose" ]; then
log "$@"
fi
}
info "argv: $(printf '%q ' "$@")"
usage () {
local code="$1"
shift
if [ "$code" -ne 0 ]; then
exec >&2
fi
echo "Usage:"
echo "$me [OPTIONS] [-- [PVL_OPTIONS]]"
echo
echo "Must be run while holding a lock."
echo
echo "Options"
echo "--deploy=DIR Ignored for backwards compatibility."
echo "--force Try even if an earlier attempt failed."
echo "--session=PATH Directory representing a session."
echo "--suite=SUITE Run in this runtime [default=choose automatically]."
echo "--use-timestamp Prepend the timestamp to the log entries."
echo "--verbose Be more verbose."
exit "${code}"
}
getopt_temp="help"
getopt_temp="${getopt_temp},deploy:"
getopt_temp="${getopt_temp},force"
getopt_temp="${getopt_temp},session:"
getopt_temp="${getopt_temp},suite:"
getopt_temp="${getopt_temp},use-timestamp:"
getopt_temp="${getopt_temp},verbose"
getopt_temp="$(getopt -o '' --long "$getopt_temp" -n "$me" -- "$@")"
eval "set -- $getopt_temp"
unset getopt_temp
while [ "$#" -gt 0 ]; do
case "$1" in
(--help)
usage 0
# not reached
;;
(--deploy)
shift 2
;;
(--force)
force=yes
shift
;;
(--session)
rendezvous="$2"
shift 2
;;
(--suite)
suite="$2"
shift 2
;;
(--use-timestamp)
use_timestamp=yes
shift
;;
(--verbose)
verbose=yes
# Propagate it to pressure-vessel too
export PRESSURE_VESSEL_VERBOSE=1
shift
;;
(--)
shift
break
;;
(-*)
log "Unknown option: $1"
usage 64 # EX_USAGE from sysexits.h
# not reached
;;
(*)
break
;;
esac
done
pressure_vessel="${PRESSURE_VESSEL_PREFIX:-"${here}/pressure-vessel"}"
if [ -z "$rendezvous" ]; then
log "A session path is required"
exit 64
fi
if [ -S "$rendezvous/socket" ]; then
info "Session already started in $rendezvous"
exit 0
fi
if [ -z "$force" ] && [ -e "$rendezvous/failed" ]; then
log "Starting session already failed, not trying again."
log "Remove $rendezvous/failed to retry."
exit 70 # EX_SOFTWARE
fi
rm -f "$rendezvous/fifo"
mkfifo "$rendezvous/fifo"
if [ -z "${suite}" ]; then
run=run
else
run="run-in-${suite}"
fi
info "Starting pressure-vessel-launcher in background"
"${here}/${run}" \
--filesystem="$pressure_vessel" \
--filesystem="$rendezvous" \
--launcher \
--pass-fd=3 \
"$@" \
-- \
--info-fd=3 \
--socket-directory="$rendezvous" \
< /dev/null >&2 3>"$rendezvous/fifo" &
container_pid="$!"
info "Started pressure-vessel-launcher in background, pid $container_pid"
socket=$(
while read -r line; do
case "$line" in
(socket=*)
echo "${line#socket=}"
break
;;
esac
done < "$rendezvous/fifo"
)
if [ -z "$socket" ] || ! [ -S "$socket" ]; then
: > "$rendezvous/failed"
log "Error starting pressure-vessel container"
if [ -z "${STEAM_LINUX_RUNTIME_VERBOSE-}" ]; then
log "Try environment variable STEAM_LINUX_RUNTIME_VERBOSE=1 for more details"
fi
kill "$container_pid" || :
exit 70 # EX_SOFTWARE
fi
ln -fns "$socket" "$rendezvous/socket"
verbose "OK, ready to exit"
exit 0
# vim:set sw=4 sts=4 et:
......@@ -186,11 +186,7 @@ if [ -n "$log_to_file" ]; then
app="app${STEAM_COMPAT_APP_ID-${SteamAppId}}"
fi
if [ -z "${STEAM_COMPAT_SESSION_ID-}" ]; then
log_filename="slr-${app}-t$(date +'%Y%m%dT%H%M%S').log"
else
log_filename="slr-${app}-s${STEAM_COMPAT_SESSION_ID}.log"
fi
log_filename="slr-${app}-t$(date +'%Y%m%dT%H%M%S').log"
mkdir -p "${log_dir}"
......@@ -201,8 +197,7 @@ if [ -n "$log_to_file" ]; then
ln -fns "${log_filename}" "${log_dir}/slr-latest.log" || :
if [[ (-z "$is_main" && -n "${STEAM_COMPAT_SESSION_ID-}")
|| -n "${PRESSURE_VESSEL_BATCH-}" ]]; then
if [ -z "$is_main" ] || [ -n "${PRESSURE_VESSEL_BATCH-}" ]; then
# If we are running setup commands, or if we are gathering a system
# information report, we only redirect stderr to the log, on the
# assumption that stderr is for human-readable diagnostics but
......@@ -223,25 +218,6 @@ if [ "$#" -eq 0 ] || [ "x$1" = x-- ]; then
usage 125
fi
# Steam App ID of this app or game
verbose "STEAM_COMPAT_APP_ID=${STEAM_COMPAT_APP_ID-}"
# Session ID used for coordination between processes involving the same game.
# If unset/empty, only execute a single command.
verbose "STEAM_COMPAT_SESSION_ID=${STEAM_COMPAT_SESSION_ID-}"
# Used to create sockets.
verbose "XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR-}"
if [ -z "${STEAM_COMPAT_SESSION_ID-}" ]; then
info "Non-session mode, behaving like the main program"
is_main=yes
elif [ -n "$is_main" ]; then
info "Main program in session mode"
else
verbose "Setup program in session mode"
fi
# At this point $LD_LIBRARY_PATH might
# 1. be equal to $STEAM_RUNTIME_LIBRARY_PATH (e.g. a game without
# any special launch options).
......@@ -295,8 +271,6 @@ IFS="$old_IFS"
unset LD_LIBRARY_PATH
unset STEAM_RUNTIME
pressure_vessel="${PRESSURE_VESSEL_PREFIX:-"${here}/pressure-vessel"}"
if [ -z "${suite}" ]; then
run=run
else
......@@ -313,100 +287,6 @@ exec_container () {
exit 125
}
if [ -z "${STEAM_COMPAT_SESSION_ID-}" ]; then
verbose "Non-session mode, just running the container"
exec_container "$@"
# not reached
fi
# Session mode. Either PRESSURE_VESSEL_SOCKET_DIR or XDG_RUNTIME_DIR are required.
verbose "Session mode"
if [[ -v PRESSURE_VESSEL_SOCKET_DIR ]]; then
if ! [ -O "$PRESSURE_VESSEL_SOCKET_DIR" ]; then
log "PRESSURE_VESSEL_SOCKET_DIR is owned by someone else"
exit 125
fi
rendezvous="${PRESSURE_VESSEL_SOCKET_DIR}/SteamLinuxRuntime.${STEAM_COMPAT_SESSION_ID:?}"
else
if ! [ -O "$XDG_RUNTIME_DIR" ]; then
log "XDG_RUNTIME_DIR is owned by someone else"
exit 125
fi
rendezvous="${XDG_RUNTIME_DIR}/SteamLinuxRuntime.${STEAM_COMPAT_SESSION_ID:?}"
fi
if mkdir -m700 "$rendezvous" 2>/dev/null; then
:
elif [ -d "$rendezvous" ] && [ -O "$rendezvous" ]; then
:
else
log "Unable to create or adopt $rendezvous"
exit 125
fi
terminate_container () {
if ! [ -S "$rendezvous/socket" ]; then
# nothing to do
return
fi
"$pressure_vessel/bin/pressure-vessel-adverb" \
--create \
--wait \
--write \
--lock-file "${rendezvous}/.ref" \
-- \
"$pressure_vessel/bin/pressure-vessel-launch" \
--socket="$rendezvous/socket" \
--terminate
}
if [ -n "$is_main" ]; then
info "Terminating and re-launching container for main game"
terminate_container || :
exec_container "$@"
# not reached
fi
# Note that if we get here, is_main must be empty.
# Launch the pressure-vessel-launcher(1). This is used to run the
# setup commands (--verb=run), if any.
#
# We have to launch pressure-vessel-launcher(1) *without* setting
# SteamAppId, SteamAppUser, etc., otherwise Steam will think the game
# is already running and refuse to run it again. (Tested with SteamAppId,
# just guessing about the others)
"$pressure_vessel/bin/pressure-vessel-adverb" \
--create \
--wait \
--write \
--lock-file "${rendezvous}/.ref" \
-- \
env \
-u FONTCONFIG_PATH \
-u SteamLauncherUI \
-u SteamAppId \
-u SteamAppUser \
-u SteamClientLaunch \
-u SteamEnv \
-u SteamGameId \
-u SteamOverlayGameId \
"${here}/_start-container-in-background" \
--session="$rendezvous" \
--suite="$suite" \
-- \
${container_args[0]+"${container_args[@]}"} \
--terminate-timeout=2 \
${NULL+}
exec "$pressure_vessel/bin/pressure-vessel-launch" \
--directory="$(pwd)" \
--socket="$rendezvous/socket" \
-- \
"$@"
exit 125
# not reached
exec_container "$@"
# vim:set sw=4 sts=4 et:
......@@ -58,9 +58,6 @@ Some more advanced environment variables (subject to change):
* `PRESSURE_VESSEL_SHELL=instead` runs an interactive shell in the
container instead of running the game.
* `STEAM_COMPAT_FORCE_SESSIONS` forces session mode when the compat tool
is used.
* See the pressure-vessel source code for more.
Licensing and copyright
......
......@@ -56,9 +56,6 @@ Some more advanced environment variables (subject to change):
* `PRESSURE_VESSEL_SHELL=instead` runs an interactive shell in the
container instead of running the game.
* `STEAM_COMPAT_FORCE_SESSIONS` forces session mode when the compat tool
is used.
* See the pressure-vessel source code for more.
Licensing and copyright
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment