Skip to content
Snippets Groups Projects

pressure-vessel: Remap preloadable modules better

Merged Simon McVittie requested to merge wip/t29490 into master
1 file
+ 46
54
Compare changes
  • Side-by-side
  • Inline
+ 46
54
@@ -696,6 +696,7 @@ static gboolean opt_remove_game_overlay = FALSE;
static gboolean opt_import_vulkan_layers = TRUE;
static PvShell opt_shell = PV_SHELL_NONE;
static GArray *opt_pass_fds = NULL;
static GArray *opt_preload_modules = NULL;
static char *opt_runtime = NULL;
static char *opt_runtime_archive = NULL;
static char *opt_runtime_base = NULL;
@@ -714,18 +715,6 @@ static gboolean opt_test = FALSE;
static PvTerminal opt_terminal = PV_TERMINAL_AUTO;
static char *opt_write_final_argv = NULL;
static PreloadModule opt_preload_modules[] =
{
{ "LD_AUDIT", NULL },
{ "LD_PRELOAD", NULL },
};
static const char * const adverb_preload_options[G_N_ELEMENTS (opt_preload_modules)] =
{
/* Must be in the same order as opt_preload_modules */
"--ld-audit",
"--ld-preload",
};
/*
* check_main_program:
*
@@ -738,39 +727,49 @@ check_main_program (int argc,
return g_getenv ("SteamAppId") != NULL;
}
static gboolean
opt_host_ld_preload_cb (const gchar *option_name,
const gchar *value,
gpointer data,
GError **error)
typedef struct
{
g_warning ("%s is deprecated, use --ld-preload=%s instead",
option_name, value);
pv_append_preload_module (opt_preload_modules, G_N_ELEMENTS (opt_preload_modules),
"LD_PRELOAD", value);
return TRUE;
const char *adverb_option;
gchar *preload;
} WrapPreloadModule;
static void
wrap_preload_module_clear (gpointer p)
{
WrapPreloadModule *self = p;
g_free (self->preload);
}
/* This can be used directly as a GOptionArgFunc if the pv-wrap option
* happens to be named the same as the pv-adverb option. */
static gboolean
opt_ld_audit_cb (const gchar *option_name,
const gchar *value,
gpointer data,
GError **error)
opt_ld_something (const char *option,
const char *value,
gpointer data,
GError **error)
{
pv_append_preload_module (opt_preload_modules, G_N_ELEMENTS (opt_preload_modules),
"LD_AUDIT", value);
WrapPreloadModule module = { option, g_strdup (value) };
if (opt_preload_modules == NULL)
{
opt_preload_modules = g_array_new (FALSE, FALSE, sizeof (WrapPreloadModule));
g_array_set_clear_func (opt_preload_modules, wrap_preload_module_clear);
}
g_array_append_val (opt_preload_modules, module);
return TRUE;
}
static gboolean
opt_ld_preload_cb (const gchar *option_name,
const gchar *value,
gpointer data,
GError **error)
opt_host_ld_preload_cb (const gchar *option_name,
const gchar *value,
gpointer data,
GError **error)
{
pv_append_preload_module (opt_preload_modules, G_N_ELEMENTS (opt_preload_modules),
"LD_PRELOAD", value);
return TRUE;
g_warning ("%s is deprecated, use --ld-preload=%s instead",
option_name, value);
return opt_ld_something ("--ld-preload", value, data, error);
}
static gboolean
@@ -1102,12 +1101,12 @@ static GOptionEntry options[] =
"container, or that needs to inherit the value from the host system, "
"will be locked. This option implies --batch.", NULL },
{ "ld-audit", '\0',
G_OPTION_FLAG_NONE, G_OPTION_ARG_CALLBACK, &opt_ld_audit_cb,
G_OPTION_FLAG_NONE, G_OPTION_ARG_CALLBACK, &opt_ld_something,
"Add MODULE from current execution environment to LD_AUDIT when "
"executing COMMAND.",
"MODULE" },
{ "ld-preload", '\0',
G_OPTION_FLAG_NONE, G_OPTION_ARG_CALLBACK, &opt_ld_preload_cb,
G_OPTION_FLAG_NONE, G_OPTION_ARG_CALLBACK, &opt_ld_something,
"Add MODULE from current execution environment to LD_PRELOAD when "
"executing COMMAND.",
"MODULE" },
@@ -2120,24 +2119,19 @@ main (int argc,
* used for them, which might be their physical rather than logical
* locations. Steam doesn't generally use LD_AUDIT, but the Steam app
* on Flathub does, and it needs similar handling. */
for (i = 0; i < G_N_ELEMENTS (opt_preload_modules); i++)
if (opt_preload_modules != NULL)
{
const char *variable = opt_preload_modules[i].variable;
const GPtrArray *values = opt_preload_modules[i].values;
const char *option = adverb_preload_options[i];
gsize len;
gsize j;
g_debug ("Adjusting %s...", variable);
if (values == NULL)
len = 0;
else
len = values->len;
g_debug ("Adjusting LD_AUDIT/LD_PRELOAD modules...");
for (j = 0; j < len; j++)
for (j = 0; j < opt_preload_modules->len; j++)
{
const char *preload = g_ptr_array_index (values, j);
const WrapPreloadModule *module = &g_array_index (opt_preload_modules,
WrapPreloadModule,
j);
const char *option = module->adverb_option;
const char *preload = module->preload;
g_assert (preload != NULL);
@@ -2146,8 +2140,7 @@ main (int argc,
if (strstr (preload, "gtk3-nocsd") != NULL)
{
g_warning ("Disabling gtk3-nocsd %s: it is known to cause crashes.",
variable);
g_warning ("Disabling gtk3-nocsd module: it is known to cause crashes.");
continue;
}
@@ -2708,8 +2701,7 @@ out:
if (local_error != NULL)
pv_log_failure ("%s", local_error->message);
pv_preload_modules_free (opt_preload_modules, G_N_ELEMENTS (opt_preload_modules));
g_clear_pointer (&opt_preload_modules, g_array_unref);
g_clear_pointer (&adverb_preload_argv, g_ptr_array_unref);
g_clear_pointer (&opt_env_if_host, g_strfreev);
g_clear_pointer (&opt_freedesktop_app_id, g_free);
Loading