# HG changeset patch
# User Volker Braun
# Date 1290031800 18000
# Node ID 6142b25d71551c4efa4184d45390d4ff030835cd
# Parent 6f1a75750df41564e077dc801163fe4ce660adff
Trac 10286: sagenativeexecute does not unset path etc.
The sagenativeexecute script unsets the LD_LIBRARY_PATH but not the PATH, and then executes the argument. So it essentially breaks execution of all programs that are shipped with sage since they can't find their libraries any more, unless you are lucky and the system libraries have the same version.
diff r 6f1a75750df4 r 6142b25d7155 sageenv
 a/sageenv Tue Nov 16 12:26:02 2010 0500
+++ b/sageenv Wed Nov 17 17:10:00 2010 0500
@@ 22,6 +22,24 @@
#
##########################################################################
+# first, save paths so we can unset them when calling external programs
+if [ z "${SAGE_ORIG_PATH_SET}" ]; then
+ SAGE_ORIG_PATH=$PATH && export SAGE_ORIG_PATH
+ SAGE_ORIG_PATH_SET=True && export SAGE_ORIG_PATH_SET
+fi
+
+if [ z "${SAGE_ORIG_LD_LIBRARY_PATH_SET}" ]; then
+ SAGE_ORIG_LD_LIBRARY_PATH=$LD_LIBRARY_PATH && export SAGE_ORIG_LD_LIBRARY_PATH
+ SAGE_ORIG_LD_LIBRARY_PATH_SET=True && export SAGE_ORIG_LD_LIBRARY_PATH_SET
+fi
+
+if [ `uname` = "Darwin" ]; then
+ if [ z "${SAGE_ORIG_DYLD_LIBRARY_PATH_SET}" ]; then
+ SAGE_ORIG_DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH && export SAGE_ORIG_DYLD_LIBRARY_PATH
+ SAGE_ORIG_DYLD_LIBRARY_PATH_SET=True && export SAGE_ORIG_DYLD_LIBRARY_PATH_SET
+ fi
+fi
+
# GUESS SAGE_ROOT from pwd
SAVEDIR="`pwd`"
if [ f sage a d spkg ]; then
@@ 173,11 +191,6 @@
PYTHONHOME="$SAGE_ROOT/local" && export PYTHONHOME
fi
if [ z "${SAGE_ORIG_LD_LIBRARY_PATH_SET}" ]; then
 SAGE_ORIG_LD_LIBRARY_PATH=$LD_LIBRARY_PATH && export SAGE_ORIG_LD_LIBRARY_PATH
 SAGE_ORIG_LD_LIBRARY_PATH_SET=True && export SAGE_ORIG_LD_LIBRARY_PATH_SET
fi

if [ z "$SAGE_TESTDIR" ]; then
SAGE_TESTDIR="$DOT_SAGE"/tmp && export SAGE_TESTDIR
fi
@@ 214,10 +227,6 @@
# The following is needed for OS X (especially for the
# Singular install).
if [ `uname` = "Darwin" ]; then
 if [ z "${SAGE_ORIG_DYLD_LIBRARY_PATH_SET}" ]; then
 SAGE_ORIG_DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH && export SAGE_ORIG_DYLD_LIBRARY_PATH
 SAGE_ORIG_DYLD_LIBRARY_PATH_SET=True && export SAGE_ORIG_DYLD_LIBRARY_PATH_SET
 fi
DYLD_LIBRARY_PATH="$LD_LIBRARY_PATH:$DYLD_LIBRARY_PATH:$SAGE_LOCAL/lib/R/lib" && export DYLD_LIBRARY_PATH
fi
diff r 6f1a75750df4 r 6142b25d7155 sagenativeexecute
 a/sagenativeexecute Tue Nov 16 12:26:02 2010 0500
+++ b/sagenativeexecute Wed Nov 17 17:10:00 2010 0500
@@ 1,9 +1,32 @@
#!/bin/sh
LD_LIBRARY_PATH=$SAGE_ORIG_LD_LIBRARY_PATH; export LD_LIBRARY_PATH
if [ `uname` = 'Darwin' ]; then
 DYLD_LIBRARY_PATH=$SAGE_ORIG_DYLD_LIBRARY_PATH
+# This script is used to run nonSage programs such as opening an
+# image viewer, magma, matlab, latex, etc.
+
+# The PATH and LD_LIBRARY_PATH will be reverted to what they were
+# before Sage was run, allowing external programs to run. You can not
+# use this script to run programs that are shipped with Sage, as they
+# and their libraries will no longer be in the search path.
+
+
+# revert all relevant paths
+if [ "x$SAGE_ORIG_PATH_SET" = "xTrue" ]; then
+ PATH=$SAGE_ORIG_PATH
+ export PATH
fi
+if [ "x$SAGE_ORIG_LD_LIBRARY_PATH_SET" = "xTrue" ]; then
+ LD_LIBRARY_PATH=$SAGE_ORIG_LD_LIBRARY_PATH
+ export LD_LIBRARY_PATH
+fi
+
+if [ "x$SAGE_ORIG_DYLD_LIBRARY_PATH" = "xTrue" ]; then
+ DYLD_LIBRARY_PATH=$SAGE_ORIG_DYLD_LIBRARY_PATH
+ export DYLD_LIBRARY_PATH
+fi
+
+unset PYTHONPATH && export PYTHONPATH
+unset PYTHONHOME && export PYTHONHOME
+
"$@"