mirror of
https://github.com/flatpak/flatpak.git
synced 2026-04-30 20:15:25 -04:00
Handle PWD env var correctly when spawning apps/builds
Propagate PWD to child, and use it (if correct) instead of getcwd as the cwd and PWD in the child. This makes things nicer if the PWD contains a symlink, as we avoid to resolve that symlink.
This commit is contained in:
@@ -2026,7 +2026,7 @@ main (int argc,
|
||||
bool writable = FALSE;
|
||||
bool writable_app = FALSE;
|
||||
bool writable_exports = FALSE;
|
||||
char old_cwd[256];
|
||||
char *old_cwd = NULL;
|
||||
int c, i;
|
||||
pid_t pid;
|
||||
int event_fd;
|
||||
@@ -2281,7 +2281,7 @@ main (int argc,
|
||||
if (mount ("", newroot, "tmpfs", MS_NODEV|MS_NOEXEC|MS_NOSUID, NULL) != 0)
|
||||
die_with_error ("Failed to mount tmpfs");
|
||||
|
||||
getcwd (old_cwd, sizeof (old_cwd));
|
||||
old_cwd = get_current_dir_name ();
|
||||
|
||||
if (chdir (newroot) != 0)
|
||||
die_with_error ("chdir");
|
||||
@@ -2517,12 +2517,21 @@ main (int argc,
|
||||
drop_caps ();
|
||||
#endif
|
||||
|
||||
if (chdir (old_cwd) < 0)
|
||||
if (chdir (old_cwd) == 0)
|
||||
{
|
||||
xsetenv ("PWD", old_cwd, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If the old cwd is not mapped, go to home */
|
||||
const char *home = getenv("HOME");
|
||||
if (home == NULL)
|
||||
home = "/";
|
||||
|
||||
chdir (home);
|
||||
xsetenv ("PWD", home, 1);
|
||||
}
|
||||
free (old_cwd);
|
||||
|
||||
/* We can't pass regular LD_LIBRARY_PATH, as it would affect the
|
||||
setuid helper aspect, so we use _LD_LIBRARY_PATH */
|
||||
|
||||
@@ -955,7 +955,6 @@ xdg_app_context_allow_host_fs (XdgAppContext *context)
|
||||
xdg_app_context_add_filesystem (context, "host");
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
extract_unix_path_from_dbus_address (const char *address)
|
||||
{
|
||||
@@ -1534,6 +1533,7 @@ xdg_app_run_get_minimal_env (gboolean devel)
|
||||
{
|
||||
GPtrArray *env_array;
|
||||
static const char * const copy[] = {
|
||||
"PWD",
|
||||
"GDMSESSION",
|
||||
"XDG_CURRENT_DESKTOP",
|
||||
"XDG_SESSION_DESKTOP",
|
||||
|
||||
Reference in New Issue
Block a user