forked from Mirrors/flatpak-builder
builtin-run: Switch over to same env helpers
parent
4ef2ba28ff
commit
6c99fcb832
|
@ -54,20 +54,6 @@ static GOptionEntry options[] = {
|
|||
{ NULL }
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
char *value;
|
||||
} EnvVar;
|
||||
|
||||
static void
|
||||
free_envvar (void *p)
|
||||
{
|
||||
EnvVar *v = (EnvVar *) p;
|
||||
g_free (v->name);
|
||||
g_free (v->value);
|
||||
g_free (v);
|
||||
}
|
||||
|
||||
static void
|
||||
add_extension_arg (const char *directory,
|
||||
const char *type, const char *extension, const char *arch, const char *branch,
|
||||
|
@ -153,30 +139,6 @@ add_extension_args (GKeyFile *metakey, const char *full_ref,
|
|||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
add_env_overrides (GKeyFile *metakey, GPtrArray *env_array)
|
||||
{
|
||||
gsize i, keys_count;
|
||||
/* Only free the array of keys, not the actual values */
|
||||
g_autofree char **keys;
|
||||
|
||||
if (!g_key_file_has_group (metakey, "Vars"))
|
||||
return;
|
||||
|
||||
keys = g_key_file_get_keys (metakey, "Vars", &keys_count, NULL);
|
||||
if (!keys)
|
||||
return;
|
||||
|
||||
for (i = 0; i < keys_count; i++)
|
||||
{
|
||||
EnvVar *var = malloc (sizeof (EnvVar));
|
||||
var->name = keys[i];
|
||||
var->value = g_key_file_get_string (metakey, "Vars", keys[i], NULL);
|
||||
|
||||
g_ptr_array_add (env_array, var);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
dbus_spawn_child_setup (gpointer user_data)
|
||||
{
|
||||
|
@ -196,9 +158,6 @@ xdg_app_builtin_run (int argc, char **argv, GCancellable *cancellable, GError **
|
|||
g_autoptr(GFile) app_files = NULL;
|
||||
g_autoptr(GFile) runtime_files = NULL;
|
||||
g_autoptr(GFile) app_id_dir = NULL;
|
||||
g_autoptr(GFile) app_id_dir_data = NULL;
|
||||
g_autoptr(GFile) app_id_dir_config = NULL;
|
||||
g_autoptr(GFile) app_id_dir_cache = NULL;
|
||||
g_autoptr(XdgAppSessionHelper) session_helper = NULL;
|
||||
g_autofree char *runtime = NULL;
|
||||
g_autofree char *default_command = NULL;
|
||||
|
@ -208,7 +167,7 @@ xdg_app_builtin_run (int argc, char **argv, GCancellable *cancellable, GError **
|
|||
g_autoptr(GKeyFile) metakey = NULL;
|
||||
g_autoptr(GKeyFile) runtime_metakey = NULL;
|
||||
g_autoptr(GPtrArray) argv_array = NULL;
|
||||
g_autoptr(GPtrArray) env_array = NULL;
|
||||
glnx_strfreev char **envp = NULL;
|
||||
g_autoptr(GPtrArray) dbus_proxy_argv = NULL;
|
||||
g_autofree char *monitor_path = NULL;
|
||||
const char *app;
|
||||
|
@ -290,18 +249,11 @@ xdg_app_builtin_run (int argc, char **argv, GCancellable *cancellable, GError **
|
|||
if (runtime_deploy == NULL)
|
||||
goto out;
|
||||
|
||||
env_array = g_ptr_array_new_with_free_func (free_envvar);
|
||||
|
||||
runtime_metakey = xdg_app_deploy_get_metadata (runtime_deploy);
|
||||
|
||||
if (!add_extension_args (runtime_metakey, runtime_ref, argv_array, cancellable, error))
|
||||
goto out;
|
||||
|
||||
add_env_overrides (runtime_metakey, env_array);
|
||||
|
||||
/* Load application environment overrides *after* runtime */
|
||||
add_env_overrides (metakey, env_array);
|
||||
|
||||
if ((app_id_dir = xdg_app_ensure_data_dir (app, cancellable, error)) == NULL)
|
||||
goto out;
|
||||
|
||||
|
@ -398,29 +350,16 @@ xdg_app_builtin_run (int argc, char **argv, GCancellable *cancellable, GError **
|
|||
|
||||
g_ptr_array_add (argv_array, NULL);
|
||||
|
||||
g_setenv ("PATH", "/self/bin:/usr/bin", TRUE);
|
||||
g_setenv ("_LD_LIBRARY_PATH", "/self/lib", TRUE);
|
||||
g_setenv ("XDG_CONFIG_DIRS","/self/etc/xdg:/etc/xdg", TRUE);
|
||||
g_setenv ("XDG_DATA_DIRS", "/self/share:/usr/share", TRUE);
|
||||
g_setenv ("GI_TYPELIB_PATH", "/self/lib/girepository-1.0", TRUE);
|
||||
envp = g_get_environ ();
|
||||
envp = xdg_app_run_apply_env_default (envp);
|
||||
|
||||
app_id_dir_data = g_file_get_child (app_id_dir, "data");
|
||||
app_id_dir_config = g_file_get_child (app_id_dir, "config");
|
||||
app_id_dir_cache = g_file_get_child (app_id_dir, "cache");
|
||||
g_setenv ("XDG_DATA_HOME", gs_file_get_path_cached (app_id_dir_data), TRUE);
|
||||
g_setenv ("XDG_CONFIG_HOME", gs_file_get_path_cached (app_id_dir_config), TRUE);
|
||||
g_setenv ("XDG_CACHE_HOME", gs_file_get_path_cached (app_id_dir_cache), TRUE);
|
||||
envp = xdg_app_run_apply_env_vars (envp, runtime_metakey);
|
||||
/* Load application environment overrides *after* runtime */
|
||||
envp = xdg_app_run_apply_env_vars (envp, metakey);
|
||||
|
||||
for (i = 0; i < env_array->len; i++)
|
||||
{
|
||||
EnvVar *var = g_ptr_array_index (env_array, i);
|
||||
if (!var->value || !var->value[0])
|
||||
g_unsetenv (var->name);
|
||||
else
|
||||
g_setenv (var->name, var->value, TRUE);
|
||||
}
|
||||
envp = xdg_app_run_apply_env_appid (envp, app_id_dir);
|
||||
|
||||
if (execv (HELPER, (char **)argv_array->pdata) == -1)
|
||||
if (execvpe (HELPER, (char **)argv_array->pdata, envp) == -1)
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno), "Unable to start app");
|
||||
goto out;
|
||||
|
|
|
@ -603,7 +603,7 @@ buffer_read (ProxySide *side,
|
|||
{
|
||||
if (res != 0)
|
||||
{
|
||||
g_warning ("Error reading from socket: %s", error->message);
|
||||
g_debug ("Error reading from socket: %s", error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
|
|
|
@ -305,26 +305,28 @@ xdg_app_run_add_environment_args (GPtrArray *argv_array,
|
|||
}
|
||||
}
|
||||
|
||||
static const struct {const char *env; const char *val;} default_exports[] = {
|
||||
{"PATH","/self/bin:/usr/bin"},
|
||||
{"_LD_LIBRARY_PATH", "/self/lib"},
|
||||
{"XDG_CONFIG_DIRS","/self/etc/xdg:/etc/xdg"},
|
||||
{"XDG_DATA_DIRS","/self/share:/usr/share"},
|
||||
{"GI_TYPELIB_PATH","/self/lib/girepository-1.0"},
|
||||
{"SHELL","/bin/sh"},
|
||||
};
|
||||
|
||||
static const struct {const char *env; const char *val;} devel_exports[] = {
|
||||
{"ACLOCAL_PATH","/self/share/aclocal"},
|
||||
{"C_INCLUDE_PATH","/self/include"},
|
||||
{"CPLUS_INCLUDE_PATH","/self/include"},
|
||||
{"LDFLAGS","-L/self/lib "},
|
||||
{"PKG_CONFIG_PATH","/self/lib/pkgconfig:/self/share/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig"},
|
||||
{"LC_ALL","en_US.utf8"},
|
||||
};
|
||||
|
||||
char **
|
||||
xdg_app_run_get_minimal_env (gboolean devel)
|
||||
{
|
||||
GPtrArray *env_array;
|
||||
static const char const *exports[] = {
|
||||
"PATH=/self/bin:/usr/bin",
|
||||
"_LD_LIBRARY_PATH=/self/lib",
|
||||
"XDG_CONFIG_DIRS=/self/etc/xdg:/etc/xdg",
|
||||
"XDG_DATA_DIRS=/self/share:/usr/share",
|
||||
"GI_TYPELIB_PATH=/self/lib/girepository-1.0",
|
||||
"SHELL=/bin/sh",
|
||||
};
|
||||
static const char const *exports_devel[] = {
|
||||
"ACLOCAL_PATH=/self/share/aclocal",
|
||||
"C_INCLUDE_PATH=/self/include",
|
||||
"CPLUS_INCLUDE_PATH=/self/include",
|
||||
"LDFLAGS=-L/self/lib ",
|
||||
"PKG_CONFIG_PATH=/self/lib/pkgconfig:/self/share/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig",
|
||||
"LC_ALL=en_US.utf8",
|
||||
};
|
||||
static const char const *copy[] = {
|
||||
"GDMSESSION",
|
||||
"XDG_CURRENT_DESKTOP",
|
||||
|
@ -360,13 +362,13 @@ xdg_app_run_get_minimal_env (gboolean devel)
|
|||
|
||||
env_array = g_ptr_array_new_with_free_func (g_free);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS(exports); i++)
|
||||
g_ptr_array_add (env_array, g_strdup (exports[i]));
|
||||
for (i = 0; i < G_N_ELEMENTS(default_exports); i++)
|
||||
g_ptr_array_add (env_array, g_strdup_printf ("%s=%s", default_exports[i].env, default_exports[i].val));
|
||||
|
||||
if (devel)
|
||||
{
|
||||
for (i = 0; i < G_N_ELEMENTS(exports_devel); i++)
|
||||
g_ptr_array_add (env_array, g_strdup (exports_devel[i]));
|
||||
for (i = 0; i < G_N_ELEMENTS(devel_exports); i++)
|
||||
g_ptr_array_add (env_array, g_strdup_printf ("%s=%s", devel_exports[i].env, devel_exports[i].val));
|
||||
}
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS(copy); i++)
|
||||
|
@ -390,6 +392,35 @@ xdg_app_run_get_minimal_env (gboolean devel)
|
|||
return (char **)g_ptr_array_free (env_array, FALSE);
|
||||
}
|
||||
|
||||
char **
|
||||
xdg_app_run_apply_env_default (char **envp)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS(default_exports); i++)
|
||||
envp = g_environ_setenv (envp, default_exports[i].env, default_exports[i].val, TRUE);
|
||||
|
||||
return envp;
|
||||
}
|
||||
|
||||
char **
|
||||
xdg_app_run_apply_env_appid (char **envp,
|
||||
GFile *app_dir)
|
||||
{
|
||||
g_autoptr(GFile) app_dir_data = NULL;
|
||||
g_autoptr(GFile) app_dir_config = NULL;
|
||||
g_autoptr(GFile) app_dir_cache = NULL;
|
||||
|
||||
app_dir_data = g_file_get_child (app_dir, "data");
|
||||
app_dir_config = g_file_get_child (app_dir, "config");
|
||||
app_dir_cache = g_file_get_child (app_dir, "cache");
|
||||
envp = g_environ_setenv (envp, "XDG_DATA_HOME", gs_file_get_path_cached (app_dir_data), TRUE);
|
||||
envp = g_environ_setenv (envp, "XDG_CONFIG_HOME", gs_file_get_path_cached (app_dir_config), TRUE);
|
||||
envp = g_environ_setenv (envp, "XDG_CACHE_HOME", gs_file_get_path_cached (app_dir_cache), TRUE);
|
||||
|
||||
return envp;
|
||||
}
|
||||
|
||||
char **
|
||||
xdg_app_run_apply_env_vars (char **envp, GKeyFile *metakey)
|
||||
{
|
||||
|
|
|
@ -31,6 +31,9 @@ void xdg_app_run_add_environment_args (GPtrArray *argv_array,
|
|||
const char **allow,
|
||||
const char **forbid);
|
||||
char ** xdg_app_run_get_minimal_env (gboolean devel);
|
||||
char ** xdg_app_run_apply_env_default (char **envp);
|
||||
char ** xdg_app_run_apply_env_appid (char **envp,
|
||||
GFile *app_dir);
|
||||
char ** xdg_app_run_apply_env_vars (char **envp,
|
||||
GKeyFile *metakey);
|
||||
|
||||
|
|
Loading…
Reference in New Issue