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

adverb: respect STEAM_COMPAT_FLAGS=search-cwd


If we have "search-cwd" in `STEAM_COMPAT_FLAGS`, and we are running the
main program, we need to append to `LD_LIBRARY_PATH` the working
directory of the game that we want to execute. Said directory is
expected to be `STEAM_COMPAT_INSTALL_PATH`.

Fixes: #46

Signed-off-by: default avatarLudovico de Nittis <ludovico.denittis@collabora.com>
parent 2c3ce248
No related branches found
No related tags found
No related merge requests found
Pipeline #6878 passed
...@@ -631,6 +631,31 @@ cli_log_func (const gchar *log_domain, ...@@ -631,6 +631,31 @@ cli_log_func (const gchar *log_domain,
g_printerr ("%s[%d]: %s\n", (const char *) user_data, my_pid, message); g_printerr ("%s[%d]: %s\n", (const char *) user_data, my_pid, message);
} }
/*
* is_main_program:
*
* Check 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
is_main_program (char *argv[])
{
gsize i;
const gchar *session_id = g_environ_getenv ((gchar **) global_original_environ,
"STEAM_COMPAT_SESSION_ID");
if (session_id == NULL)
/* Non-session mode, behaving like the main program */
return TRUE;
for (i = 0; argv[i] != NULL; i++)
{
if (g_strcmp0 (argv[i], "waitforexitandrun") == 0)
return TRUE;
}
return FALSE;
}
int int
main (int argc, main (int argc,
char *argv[]) char *argv[])
...@@ -648,6 +673,8 @@ main (int argc, ...@@ -648,6 +673,8 @@ main (int argc,
sigset_t mask; sigset_t mask;
struct sigaction terminate_child_action = {}; struct sigaction terminate_child_action = {};
g_autoptr(FlatpakBwrap) wrapped_command = NULL; g_autoptr(FlatpakBwrap) wrapped_command = NULL;
gboolean search_cwd = FALSE;
const gchar *steam_compat_flags = NULL;
my_pid = getpid (); my_pid = getpid ();
...@@ -837,6 +864,39 @@ main (int argc, ...@@ -837,6 +864,39 @@ main (int argc,
} }
} }
steam_compat_flags = g_environ_getenv (original_environ, "STEAM_COMPAT_FLAGS");
if (steam_compat_flags != NULL)
{
g_auto(GStrv) flags = g_strsplit (steam_compat_flags, ",", -1);
for (gsize i = 0; flags[i] != NULL; i++)
{
if (g_strcmp0 (flags[i], "search-cwd") == 0)
search_cwd = TRUE;
}
}
if (search_cwd && is_main_program (argv))
{
/* This option is used for legacy purposes to cope with games that
* relied on LD_LIBRARY_PATH ending with a colon, which ld.so interprets
* as the current working directory. But because it was a bug, rather
* than a feature, it has been removed, breaking, as a result, a few
* games. */
const gchar *install_path = g_environ_getenv (original_environ,
"STEAM_COMPAT_INSTALL_PATH");
const gchar *ld_library_path = g_environ_getenv (original_environ,
"LD_LIBRARY_PATH");
g_autofree gchar *new_ld_library_path = NULL;
if (ld_library_path != NULL)
new_ld_library_path = g_strdup_printf ("%s:%s", ld_library_path, install_path);
else
new_ld_library_path = g_strdup_printf ("%s", install_path);
flatpak_bwrap_set_env (wrapped_command, "LD_LIBRARY_PATH", new_ld_library_path, TRUE);
}
/* Respond to common termination signals by killing the child instead of /* Respond to common termination signals by killing the child instead of
* ourselves */ * ourselves */
terminate_child_action.sa_handler = terminate_child_cb; terminate_child_action.sa_handler = terminate_child_cb;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment