instance: Add flatpak_instance_get_run_environ()

This private function returns the environment in which flatpak-run
was executed for a given FlatpakInstance.
This commit is contained in:
Dor Askayo
2023-06-07 01:17:38 +03:00
committed by Simon McVittie
parent 5a7ea354d3
commit df4e98fc15
2 changed files with 26 additions and 0 deletions

View File

@@ -21,6 +21,8 @@
#ifndef __FLATPAK_INSTANCE_PRIVATE_H__
#define __FLATPAK_INSTANCE_PRIVATE_H__
#include <glib.h>
#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__ */

View File

@@ -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)
{