Skip to content

Commit

Permalink
Do not use loop to check for launcher
Browse files Browse the repository at this point in the history
Do not use a loop to sleep until the Steam Runtime
launcher has finished starting up. Instead, create a pipe and pass it to
the underlying `steam-runtime-launcher-service` executable; the
executable will write to it and close it to indicate the launcher has
finished starting up.

After this every subsequent `wine_launch.sh` invocation can assume the
launcher is up instead of checking for the socket in a loop.

This approach was suggested by @smcv on GitHub.

Fixes #231
  • Loading branch information
Matoking committed Jun 18, 2023
1 parent f54e1fc commit 0b88463
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
8 changes: 6 additions & 2 deletions src/protontricks/data/scripts/bwrap_launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ done
log_info "Following directories will be mounted inside container: ${mount_dirs[*]}"
log_info "Using temporary directory: $PROTONTRICKS_TEMP_PATH"

exec "$STEAM_RUNTIME_PATH"/run --share-pid --launcher \
# Protontricks will listen to this file descriptor. Once it's closed,
# the launcher has finished starting up.
status_fd="$1"

exec "$STEAM_RUNTIME_PATH"/run --share-pid --launcher --pass-fd "$status_fd" \
"${mount_params[@]}" -- \
--bus-name="com.github.Matoking.protontricks.App${STEAM_APPID}_${PROTONTRICKS_SESSION_ID}"
--info-fd "$status_fd" --bus-name="com.github.Matoking.protontricks.App${STEAM_APPID}_${PROTONTRICKS_SESSION_ID}"
8 changes: 0 additions & 8 deletions src/protontricks/data/scripts/wine_launch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,6 @@ elif [[ "$PROTONTRICKS_STEAM_RUNTIME" = "bwrap" ]]; then
# expose the unique host PID.
bus_name="com.github.Matoking.protontricks.App${STEAM_APPID}_${PROTONTRICKS_SESSION_ID}"

# Wait until socket is created
if ! dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ListNames | grep -q "$bus_name"; then
log_info "bwrap-launcher D-Bus object not yet available, waiting..."
while ! dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ListNames | grep -q "$bus_name"; do
sleep 0.25
done
fi

# Pass all environment variables to 'steam-runtime-launch-client' except
# for problematic variables that should be determined by the launch command
# instead.
Expand Down
20 changes: 17 additions & 3 deletions src/protontricks/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,13 +474,27 @@ def run_command(
"Starting bwrap launcher process: %s",
str(wine_bin_dir / "bwrap-launcher")
)

# TODO: Waiting for launcher to start can be simplified once
# ValveSoftware/steam-runtime#593 has been fixed and stdout can
# be used instead.
launcher_read_fd, launcher_write_fd = os.pipe2(os.O_CLOEXEC)
launcher_process = _start_process(
str(wine_bin_dir / "bwrap-launcher"),
[str(wine_bin_dir / "bwrap-launcher"), str(launcher_write_fd)],
wait=False,
env=wine_environ,
stdout=DEVNULL,
pass_fds=[launcher_write_fd],
env=wine_environ
)

# The Steam Runtime launcher service will write to the given
# file descriptor and then close it to indicate the launcher is
# ready.
os.close(launcher_write_fd)
with open(launcher_read_fd, "rb") as reader:
reader.read()
# Launcher has finished starting up once output is returned
logger.info("bwrap launcher started")

if start_wineserver:
logger.info(
"Starting wineserver keepalive process: %s",
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def test_run_winetricks_steam_runtime_v2(

# Launcher process was launched to handle launching processes
# inside the sandbox
assert commands[0].args == str(wine_bin_dir / "bwrap-launcher")
assert commands[0].args[0] == str(wine_bin_dir / "bwrap-launcher")

# winecfg was run
command = commands[-1]
Expand Down

0 comments on commit 0b88463

Please sign in to comment.