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:
Alexander Larsson
2015-11-25 13:16:33 +01:00
parent dcd17f82a5
commit 787fdee634
2 changed files with 13 additions and 4 deletions

View File

@@ -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 */

View File

@@ -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",