diff options
author | Michael Stone <michael@laptop.org> | 2010-09-24 00:41:42 (GMT) |
---|---|---|
committer | Michael Stone <michael@laptop.org> | 2010-09-24 02:10:55 (GMT) |
commit | 532d4f56723afc2993a7b4ab6f863461225b22d6 (patch) | |
tree | f3ad0078bd874a194a2545674d14c74902ca809b | |
parent | 633b1f0944eff610d8323a6e1d0591a170323ff1 (diff) |
Abstract out the procedure for reading parent environment variables.
-rwxr-xr-x | bin/rainbow-easy | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/bin/rainbow-easy b/bin/rainbow-easy index dafb9c0..061f5d7 100755 --- a/bin/rainbow-easy +++ b/bin/rainbow-easy @@ -10,17 +10,21 @@ if [ -z "$1" ] || [ -z "$SUDO_USER" ]; then usage || exit 1; fi ID="$1"; shift -if [ -z "$DISPLAY" ]; then - DISPLAY=`python <<EOF +read_parent_envvar () { +python <<EOF import os from os.path import join ppid = os.getppid() env = open(join('/proc', str(ppid),'environ')).read().split('\0') for kv in env: - if kv.startswith("DISPLAY="): - print kv[len("DISPLAY="):] -EOF` + if kv.startswith("$1="): + print kv[len("$1="):] +EOF +} + +if [ -z "$DISPLAY" ]; then + DISPLAY=`read_parent_envvar DISPLAY` fi exec /usr/sbin/rainbow-run \ |