summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2016-02-19 11:53:31 +0100
committerAlexander Larsson <alexl@redhat.com>2016-02-19 11:53:31 +0100
commit1cfadbd225b442d727712becea1b96c917d818f2 (patch)
tree478356b4393e6fa84edb859a581b67f3574c0bee
parentefc900c9e7785a6f6a383ec74ccf5c7de458b286 (diff)
downloadbubblewrap-1cfadbd225b442d727712becea1b96c917d818f2.tar.gz
Add --setenv and --unsetenv args
-rw-r--r--bubblewrap.c32
-rwxr-xr-xdemos/xdg-app-run.sh27
2 files changed, 35 insertions, 24 deletions
diff --git a/bubblewrap.c b/bubblewrap.c
index b04844d..3e0a2fe 100644
--- a/bubblewrap.c
+++ b/bubblewrap.c
@@ -147,6 +147,8 @@ usage ()
" --make-symlink SRC DEST Create symlink at DEST with target SRC\n"
" --lock-file DEST Take a lock on DEST while sandbox is running\n"
" --sync-fd FD Keep this fd open while sandbox is running\n"
+ " --setenv VAR VALUE Set an environment variable\n"
+ " --unsetenv VAR Unset an environment variable\n"
);
exit (1);
}
@@ -979,6 +981,26 @@ main (int argc,
argv += 1;
argc -= 1;
}
+ else if (strcmp (arg, "--setenv") == 0)
+ {
+ if (argc < 3)
+ die ("--setenv takes two arguments");
+
+ xsetenv (argv[1], argv[2], 1);
+
+ argv += 2;
+ argc -= 2;
+ }
+ else if (strcmp (arg, "--unsetenv") == 0)
+ {
+ if (argc < 2)
+ die ("--unsetenv takes an argument");
+
+ xunsetenv (argv[1]);
+
+ argv += 1;
+ argc -= 1;
+ }
else if (*arg == '-')
die ("Unknown option %s", arg);
else
@@ -1215,16 +1237,6 @@ main (int argc,
xsetenv ("PWD", new_cwd, 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 */
- if (getenv ("_LD_LIBRARY_PATH"))
- {
- xsetenv ("LD_LIBRARY_PATH", getenv("_LD_LIBRARY_PATH"), 1);
- xunsetenv ("_LD_LIBRARY_PATH");
- }
- else
- xunsetenv ("LD_LIBRARY_PATH"); /* Make sure to unset if it was not (i.e. unprivileged mode) */
-
__debug__(("forking for child\n"));
if (unshare_pid || lock_files != NULL || sync_fd != -1)
diff --git a/demos/xdg-app-run.sh b/demos/xdg-app-run.sh
index e497872..03c37bc 100755
--- a/demos/xdg-app-run.sh
+++ b/demos/xdg-app-run.sh
@@ -5,20 +5,6 @@
# xdg-app --user install gnome-nightly org.gnome.Platform
# xdg-app --user install gnome-nightly org.gnome.Weather
-export XDG_RUNTIME_DIR="/run/user/`id -u`"
-export DISPLAY=:99
-export GI_TYPELIB_PATH=/app/lib/girepository-1.0
-export GST_PLUGIN_PATH=/app/lib/gstreamer-1.0
-export _LD_LIBRARY_PATH=/app/lib:/usr/lib/GL
-export DCONF_USER_CONFIG_DIR=.config/dconf
-export PATH=/app/bin:/usr/bin
-export XDG_CONFIG_DIRS=/app/etc/xdg:/etc/xdg
-export XDG_DATA_DIRS=/app/share:/usr/share
-export SHELL=/bin/sh
-export XDG_CACHE_HOME=~/.var/app/org.gnome.Weather/cache
-export XDG_CONFIG_HOME=~/.var/app/org.gnome.Weather/config
-export XDG_DATA_HOME=~/.var/app/org.gnome.Weather/data
-
mkdir -p ~/.var/app/org.gnome.Weather/cache ~/.var/app/org.gnome.Weather/config ~/.var/app/org.gnome.Weather/data
# These temporary files are left on the filesystem, but one can avoid
@@ -68,6 +54,19 @@ exec ../bwrap \
--mount-bind ~/.config/dconf ~/.config/dconf \
--mount-bind /run/user/`id -u`/dconf /run/user/`id -u`/dconf \
--unshare-pid \
+ --setenv XDG_RUNTIME_DIR "/run/user/`id -u`" \
+ --setenv DISPLAY :99 \
+ --setenv GI_TYPELIB_PATH /app/lib/girepository-1.0 \
+ --setenv GST_PLUGIN_PATH /app/lib/gstreamer-1.0 \
+ --setenv LD_LIBRARY_PATH /app/lib:/usr/lib/GL \
+ --setenv DCONF_USER_CONFIG_DIR .config/dconf \
+ --setenv PATH /app/bin:/usr/bin \
+ --setenv XDG_CONFIG_DIRS /app/etc/xdg:/etc/xdg \
+ --setenv XDG_DATA_DIRS /app/share:/usr/share \
+ --setenv SHELL /bin/sh \
+ --setenv XDG_CACHE_HOME ~/.var/app/org.gnome.Weather/cache \
+ --setenv XDG_CONFIG_HOME ~/.var/app/org.gnome.Weather/config \
+ --setenv XDG_DATA_HOME ~/.var/app/org.gnome.Weather/data \
sh 10< ${APPINFO} 11< ${PASSWD} 12< ${GROUP}