Skip to content
Snippets Groups Projects
Commit 9ed64292 authored by Ludovico de Nittis's avatar Ludovico de Nittis
Browse files

pressure-vessel: Add support for the env var STEAM_COMPAT_FLAGS


Respect the `STEAM_COMPAT_FLAGS` values in pressure-vessel.

Currently the only expected flag is `search-cwd` that is used to append
the game current working directory, stored in
`STEAM_COMPAT_INSTALL_PATH`, to the `LD_LIBRARY_PATH`.

Fixes: #46

Signed-off-by: default avatarLudovico de Nittis <ludovico.denittis@collabora.com>
parent 22e43459
No related branches found
No related tags found
No related merge requests found
Pipeline #9698 passed
...@@ -4665,6 +4665,17 @@ pv_runtime_set_search_paths (PvRuntime *self, ...@@ -4665,6 +4665,17 @@ pv_runtime_set_search_paths (PvRuntime *self,
pv_search_path_append (ld_library_path, ld_path); 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 /* 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. */ * puts terminfo, even if we're using a non-Debian-based libtinfo.so.6. */
terminfo_path = g_build_filename (self->source_files, "lib", "terminfo", terminfo_path = g_build_filename (self->source_files, "lib", "terminfo",
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
* @PV_RUNTIME_FLAGS_UNPACK_ARCHIVE: Source is an archive, not a deployment * @PV_RUNTIME_FLAGS_UNPACK_ARCHIVE: Source is an archive, not a deployment
* @PV_RUNTIME_FLAGS_FLATPAK_SUBSANDBOX: The runtime will be used in a * @PV_RUNTIME_FLAGS_FLATPAK_SUBSANDBOX: The runtime will be used in a
* Flatpak subsandbox * Flatpak subsandbox
* @PV_RUNTIME_FLAGS_SEARCH_CWD: Append the game install path to LD_LIBRARY_PATH
* @PV_RUNTIME_FLAGS_NONE: None of the above * @PV_RUNTIME_FLAGS_NONE: None of the above
* *
* Flags affecting how we set up the runtime. * Flags affecting how we set up the runtime.
...@@ -56,6 +57,7 @@ typedef enum ...@@ -56,6 +57,7 @@ typedef enum
PV_RUNTIME_FLAGS_COPY_RUNTIME = (1 << 5), PV_RUNTIME_FLAGS_COPY_RUNTIME = (1 << 5),
PV_RUNTIME_FLAGS_UNPACK_ARCHIVE = (1 << 6), PV_RUNTIME_FLAGS_UNPACK_ARCHIVE = (1 << 6),
PV_RUNTIME_FLAGS_FLATPAK_SUBSANDBOX = (1 << 7), PV_RUNTIME_FLAGS_FLATPAK_SUBSANDBOX = (1 << 7),
PV_RUNTIME_FLAGS_SEARCH_CWD = (1 << 8),
PV_RUNTIME_FLAGS_NONE = 0 PV_RUNTIME_FLAGS_NONE = 0
} PvRuntimeFlags; } PvRuntimeFlags;
...@@ -68,6 +70,7 @@ typedef enum ...@@ -68,6 +70,7 @@ typedef enum
| PV_RUNTIME_FLAGS_COPY_RUNTIME \ | PV_RUNTIME_FLAGS_COPY_RUNTIME \
| PV_RUNTIME_FLAGS_UNPACK_ARCHIVE \ | PV_RUNTIME_FLAGS_UNPACK_ARCHIVE \
| PV_RUNTIME_FLAGS_FLATPAK_SUBSANDBOX \ | PV_RUNTIME_FLAGS_FLATPAK_SUBSANDBOX \
| PV_RUNTIME_FLAGS_SEARCH_CWD \
) )
typedef struct _PvRuntime PvRuntime; typedef struct _PvRuntime PvRuntime;
......
...@@ -723,6 +723,31 @@ append_preload_module (const char *variable, ...@@ -723,6 +723,31 @@ append_preload_module (const char *variable,
return TRUE; return TRUE;
} }
/*
* check_main_program:
*
* Return %TRUE if the command to execute is the main program.
* The check used is similar to the one in _v2-entry-point.
* Try to keep them in sync.
*/
static gboolean
check_main_program (int argc,
char *argv[])
{
gsize i;
const gchar *session_id = g_getenv ("STEAM_COMPAT_SESSION_ID");
if (session_id == NULL)
/* Non-session mode, behaving like the main program */
return TRUE;
for (i = 0; i < argc; i++)
{
if (g_strcmp0 (argv[i], "waitforexitandrun") == 0)
return TRUE;
}
return FALSE;
}
static gboolean static gboolean
opt_host_ld_preload_cb (const gchar *option_name, opt_host_ld_preload_cb (const gchar *option_name,
const gchar *value, const gchar *value,
...@@ -1277,6 +1302,8 @@ main (int argc, ...@@ -1277,6 +1302,8 @@ main (int argc,
g_auto(GStrv) original_environ = NULL; g_auto(GStrv) original_environ = NULL;
int original_argc = argc; int original_argc = argc;
gboolean is_flatpak_env = g_file_test ("/.flatpak-info", G_FILE_TEST_IS_REGULAR); 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_subsandbox = NULL;
g_autoptr(FlatpakBwrap) flatpak_run_on_host = NULL; g_autoptr(FlatpakBwrap) flatpak_run_on_host = NULL;
g_autoptr(PvEnviron) container_env = NULL; g_autoptr(PvEnviron) container_env = NULL;
...@@ -1291,6 +1318,7 @@ main (int argc, ...@@ -1291,6 +1318,7 @@ main (int argc,
g_autofree gchar *cwd_l = NULL; g_autofree gchar *cwd_l = NULL;
g_autofree gchar *cwd_p_host = NULL; g_autofree gchar *cwd_p_host = NULL;
const gchar *home; const gchar *home;
const gchar *steam_compat_flags;
g_autofree gchar *tools_dir = NULL; g_autofree gchar *tools_dir = NULL;
g_autoptr(PvRuntime) runtime = NULL; g_autoptr(PvRuntime) runtime = NULL;
g_autoptr(FILE) original_stdout = NULL; g_autoptr(FILE) original_stdout = NULL;
...@@ -1326,6 +1354,8 @@ main (int argc, ...@@ -1326,6 +1354,8 @@ main (int argc,
if (is_flatpak_env) if (is_flatpak_env)
opt_copy_runtime = TRUE; opt_copy_runtime = TRUE;
is_main_program = check_main_program (argc, argv);
/* Set defaults */ /* Set defaults */
opt_batch = pv_boolean_environment ("PRESSURE_VESSEL_BATCH", FALSE); opt_batch = pv_boolean_environment ("PRESSURE_VESSEL_BATCH", FALSE);
/* Process COPY_RUNTIME_INFO first so that COPY_RUNTIME and VARIABLE_DIR /* Process COPY_RUNTIME_INFO first so that COPY_RUNTIME and VARIABLE_DIR
...@@ -1881,6 +1911,23 @@ main (int argc, ...@@ -1881,6 +1911,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) if (opt_runtime != NULL || opt_runtime_archive != NULL)
{ {
PvRuntimeFlags flags = PV_RUNTIME_FLAGS_NONE; PvRuntimeFlags flags = PV_RUNTIME_FLAGS_NONE;
...@@ -1908,6 +1955,12 @@ main (int argc, ...@@ -1908,6 +1955,12 @@ main (int argc,
if (flatpak_subsandbox != NULL) if (flatpak_subsandbox != NULL)
flags |= PV_RUNTIME_FLAGS_FLATPAK_SUBSANDBOX; 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) if (opt_runtime != NULL)
{ {
/* already checked for mutually exclusive options */ /* already checked for mutually exclusive options */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment