The standalone builds now unset their special path and library path variables before running the system web browser.

Should fix a crash reported on OSX.
This commit is contained in:
Joey Hess 2012-11-27 17:05:29 -04:00
parent 6a9ba6ad06
commit 2525fefbb9
6 changed files with 49 additions and 4 deletions

View file

@ -21,6 +21,7 @@ import Utility.OSX
import Utility.FreeDesktop
#endif
import Data.AssocList
import System.Posix.Env
standaloneAppBase :: IO (Maybe FilePath)
@ -68,3 +69,24 @@ ensureInstalled = go =<< standaloneAppBase
createDirectoryIfMissing True (parentDir shim)
writeFile shim content
modifyFileMode shim $ addModes [ownerExecuteMode]
{- Returns a cleaned up environment that lacks settings used to make the
- standalone builds use their bundled libraries and programs.
- Useful when calling programs not included in the standalone builds.
-
- For a non-standalone build, returns Nothing.
-}
cleanEnvironment :: IO (Maybe [(String, String)])
cleanEnvironment = clean <$> getEnvironment
where
clean env
| null vars = Nothing
| otherwise = Just $ catMaybes $ map (restoreorig env) env
| otherwise = Nothing
where
vars = words $ lookup1 "GIT_ANNEX_STANDLONE_ENV" env
restoreorig oldenv p@(k, v)
| k `elem` vars = case lookup1 ("ORIG_" ++ k) oldenv of
"" -> Nothing
v' -> Just (k, v')
| otherwise = Just p

View file

@ -137,9 +137,10 @@ openBrowser cmd htmlshim = go $ maybe runBrowser runCustomBrowser cmd
go a = do
putStrLn ""
putStrLn $ "Launching web browser on " ++ url
unlessM (a url) $
env <- cleanEnvironment
unlessM (a url env) $
error $ "failed to start web browser"
runCustomBrowser c u = boolSystem c [Param u]
runCustomBrowser c u = boolSystemEnv c [Param u]
{- web.browser is a generic git config setting for a web browser program -}
webBrowser :: Git.Repo -> Maybe FilePath

View file

@ -41,8 +41,8 @@ localhost = "localhost"
{- Runs a web browser on a given url.
-
- Note: The url *will* be visible to an attacker. -}
runBrowser :: String -> IO Bool
runBrowser url = boolSystem cmd [Param url]
runBrowser :: String -> (Maybe [(String, String)]) -> IO Bool
runBrowser url env = boolSystemEnv cmd [Param url] env
where
#ifdef darwin_HOST_OS
cmd = "open"

2
debian/changelog vendored
View file

@ -4,6 +4,8 @@ git-annex (3.20121127) UNRELEASED; urgency=low
subdirectories. Could affect various parts of git-annex.
* rsync: Fix bug introduced in last release that broke encrypted rsync
special remotes.
* The standalone builds now unset their special path and library path
variables before running the system web browser.
-- Joey Hess <joeyh@debian.org> Mon, 26 Nov 2012 16:45:19 -0400

View file

@ -41,17 +41,27 @@ fi
# Put our binaries first, to avoid issues with out of date or incompatable
# system binaries.
ORIG_PATH="$PATH"
export ORIG_PATH
PATH=$base/bin:$PATH
export PATH
ORIG_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"
export ORIG_LD_LIBRARY_PATH
for lib in $(cat $base/libdirs); do
LD_LIBRARY_PATH="$base/$lib:$LD_LIBRARY_PATH"
done
export LD_LIBRARY_PATH
ORIG_GIT_EXEC_PATH="$GIT_EXEC_PATH"
export ORIG_GIT_EXEC_PATH
GIT_EXEC_PATH=$base/git-core
export GIT_EXEC_PATH
# Indicate which variables were exported above.
GIT_ANNEX_STANDLONE_ENV="PATH LD_LIBRARY_PATH GIT_EXEC_PATH"
export GIT_ANNEX_STANDLONE_ENV
if [ "$1" ]; then
cmd="$1"
shift 1

View file

@ -41,6 +41,8 @@ fi
# Put our binaries first, to avoid issues with out of date or incompatable
# system binaries.
ORIG_PATH="$PATH"
export ORIG_PATH
PATH=$base/bin:$PATH
export PATH
@ -53,12 +55,20 @@ export PATH
# different versions of a single library. And it seems to work better
# than DYLD_FALLBACK_LIBRARY_PATH, which fails to override old system
# versions of libraries when a program in the app needs a newer version.
ORIG_DYLD_ROOT_PATH="$DYLD_ROOT_PATH"
export ORIG_DYLD_ROOT_PATH
DYLD_ROOT_PATH=$base
export DYLD_ROOT_PATH
ORIG_GIT_EXEC_PATH="$GIT_EXEC_PATH"
export ORIG_GIT_EXEC_PATH
GIT_EXEC_PATH=$base/git-core
export GIT_EXEC_PATH
# Indicate which variables were exported above.
GIT_ANNEX_STANDLONE_ENV="PATH DYLD_ROOT_PATH GIT_EXEC_PATH"
export GIT_ANNEX_STANDLONE_ENV
if [ "$1" ]; then
cmd="$1"
shift 1