From df4e98fc1529cc735ed1a10ed1b23ba9a0b72383 Mon Sep 17 00:00:00 2001 From: Dor Askayo Date: Wed, 7 Jun 2023 01:17:38 +0300 Subject: [PATCH] instance: Add flatpak_instance_get_run_environ() This private function returns the environment in which flatpak-run was executed for a given FlatpakInstance. --- common/flatpak-instance-private.h | 5 +++++ common/flatpak-instance.c | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/common/flatpak-instance-private.h b/common/flatpak-instance-private.h index 97ad874b..84d80338 100644 --- a/common/flatpak-instance-private.h +++ b/common/flatpak-instance-private.h @@ -21,6 +21,8 @@ #ifndef __FLATPAK_INSTANCE_PRIVATE_H__ #define __FLATPAK_INSTANCE_PRIVATE_H__ +#include + #include "flatpak-instance.h" FlatpakInstance *flatpak_instance_new (const char *dir); @@ -58,4 +60,7 @@ gboolean flatpak_instance_ensure_per_app_xdg_runtime_dir (const char *app_id, char **shared_dir_out, GError **error); +GStrv flatpak_instance_get_run_environ (FlatpakInstance *self, GError **error); + + #endif /* __FLATPAK_INSTANCE_PRIVATE_H__ */ diff --git a/common/flatpak-instance.c b/common/flatpak-instance.c index 075a9296..2803d4ee 100644 --- a/common/flatpak-instance.c +++ b/common/flatpak-instance.c @@ -313,6 +313,27 @@ flatpak_instance_get_info (FlatpakInstance *self) return priv->info; } +GStrv +flatpak_instance_get_run_environ (FlatpakInstance *self, GError **error) +{ + FlatpakInstancePrivate *priv = flatpak_instance_get_instance_private (self); + g_autofree char *file = NULL; + g_autofree char *environ_data = NULL; + gsize environ_size; + g_auto(GStrv) env_vars = NULL; + + file = g_build_filename (priv->private_dir, "run-environ", NULL); + + if (!g_file_get_contents (file, &environ_data, &environ_size, error)) + return NULL; + + env_vars = flatpak_parse_env_block (environ_data, environ_size, error); + if (env_vars == NULL) + return NULL; + + return g_steal_pointer (&env_vars); +} + static GKeyFile * get_instance_info (const char *dir) {