diff --git a/pressure-vessel/runtime.c b/pressure-vessel/runtime.c index 8da0c03175b246dc89771ec70b128c4ba0631a3c..ffd59dbec1ce3af5ad9f4fdf29040a5c168864dd 100644 --- a/pressure-vessel/runtime.c +++ b/pressure-vessel/runtime.c @@ -4665,6 +4665,17 @@ pv_runtime_set_search_paths (PvRuntime *self, pv_search_path_append (ld_library_path, ld_path); } + if (self->flags & PV_RUNTIME_FLAGS_SEARCH_CWD) + { + const gchar *install_path = g_environ_getenv (self->original_environ, + "STEAM_COMPAT_INSTALL_PATH"); + if (install_path != NULL) + pv_search_path_append (ld_library_path, install_path); + else + g_debug ("The environment variable \"STEAM_COMPAT_INSTALL_PATH\" is not set, " + "we can't append the game install path to LD_LIBRARY_PATH."); + } + /* If the runtime is Debian-based, make sure we search where ncurses-base * puts terminfo, even if we're using a non-Debian-based libtinfo.so.6. */ terminfo_path = g_build_filename (self->source_files, "lib", "terminfo", diff --git a/pressure-vessel/runtime.h b/pressure-vessel/runtime.h index 958577e5c69c38e3bf0958883046d7ac084eaba7..6b3b91da926f63433f3f9b7e3fd40ef68c3ca20f 100644 --- a/pressure-vessel/runtime.h +++ b/pressure-vessel/runtime.h @@ -42,6 +42,7 @@ * @PV_RUNTIME_FLAGS_UNPACK_ARCHIVE: Source is an archive, not a deployment * @PV_RUNTIME_FLAGS_FLATPAK_SUBSANDBOX: The runtime will be used in a * Flatpak subsandbox + * @PV_RUNTIME_FLAGS_SEARCH_CWD: Append the game install path to LD_LIBRARY_PATH * @PV_RUNTIME_FLAGS_NONE: None of the above * * Flags affecting how we set up the runtime. @@ -56,6 +57,7 @@ typedef enum PV_RUNTIME_FLAGS_COPY_RUNTIME = (1 << 5), PV_RUNTIME_FLAGS_UNPACK_ARCHIVE = (1 << 6), PV_RUNTIME_FLAGS_FLATPAK_SUBSANDBOX = (1 << 7), + PV_RUNTIME_FLAGS_SEARCH_CWD = (1 << 8), PV_RUNTIME_FLAGS_NONE = 0 } PvRuntimeFlags; @@ -68,6 +70,7 @@ typedef enum | PV_RUNTIME_FLAGS_COPY_RUNTIME \ | PV_RUNTIME_FLAGS_UNPACK_ARCHIVE \ | PV_RUNTIME_FLAGS_FLATPAK_SUBSANDBOX \ + | PV_RUNTIME_FLAGS_SEARCH_CWD \ ) typedef struct _PvRuntime PvRuntime; diff --git a/pressure-vessel/wrap.c b/pressure-vessel/wrap.c index 80865c7c9d0c6a6ff9bda5b6bd912a92785fac11..2f2cf85adcd0e9493a465510c7eb7f0b90be19e8 100644 --- a/pressure-vessel/wrap.c +++ b/pressure-vessel/wrap.c @@ -723,6 +723,18 @@ append_preload_module (const char *variable, return TRUE; } +/* + * check_main_program: + * + * Return %TRUE if the command to execute is the main program. + */ +static gboolean +check_main_program (int argc, + char *argv[]) +{ + return g_getenv ("SteamAppId") != NULL; +} + static gboolean opt_host_ld_preload_cb (const gchar *option_name, const gchar *value, @@ -1277,6 +1289,8 @@ main (int argc, g_auto(GStrv) original_environ = NULL; int original_argc = argc; gboolean is_flatpak_env = g_file_test ("/.flatpak-info", G_FILE_TEST_IS_REGULAR); + gboolean is_main_program; + gboolean search_cwd = FALSE; g_autoptr(FlatpakBwrap) flatpak_subsandbox = NULL; g_autoptr(FlatpakBwrap) flatpak_run_on_host = NULL; g_autoptr(PvEnviron) container_env = NULL; @@ -1291,6 +1305,7 @@ main (int argc, g_autofree gchar *cwd_l = NULL; g_autofree gchar *cwd_p_host = NULL; const gchar *home; + const gchar *steam_compat_flags; g_autofree gchar *tools_dir = NULL; g_autoptr(PvRuntime) runtime = NULL; g_autoptr(FILE) original_stdout = NULL; @@ -1326,6 +1341,8 @@ main (int argc, if (is_flatpak_env) opt_copy_runtime = TRUE; + is_main_program = check_main_program (argc, argv); + /* Set defaults */ opt_batch = pv_boolean_environment ("PRESSURE_VESSEL_BATCH", FALSE); /* Process COPY_RUNTIME_INFO first so that COPY_RUNTIME and VARIABLE_DIR @@ -1881,6 +1898,23 @@ main (int argc, } } + steam_compat_flags = g_getenv ("STEAM_COMPAT_FLAGS"); + if (steam_compat_flags != NULL) + { + g_auto(GStrv) flags = g_strsplit (steam_compat_flags, ",", -1); + for (i = 0; flags[i] != NULL; i++) + { + if (g_strcmp0 (flags[i], "search-cwd") == 0) + /* This option is used to append the game install path to + * LD_LIBRARY_PATH for legacy purposes, to cope with games that + * relied on the old behaviour of LD_LIBRARY_PATH of ending with + * a colon, which ld.so interprets as the current working directory. */ + search_cwd = TRUE; + else + g_info ("STEAM_COMPAT_FLAGS has the unexpected flag \"%s\"", flags[i]); + } + } + if (opt_runtime != NULL || opt_runtime_archive != NULL) { PvRuntimeFlags flags = PV_RUNTIME_FLAGS_NONE; @@ -1908,6 +1942,12 @@ main (int argc, if (flatpak_subsandbox != NULL) flags |= PV_RUNTIME_FLAGS_FLATPAK_SUBSANDBOX; + /* Only if we are running the main program, append the working directory + * of the game to LD_LIBRARY_PATH. This option is not intended for the + * setup phase. */ + if (search_cwd && is_main_program) + flags |= PV_RUNTIME_FLAGS_SEARCH_CWD; + if (opt_runtime != NULL) { /* already checked for mutually exclusive options */