[GHC] #12377: getExecutablePath doesn't return absolute path on OpenBSD (and maybe other OS also)

#12377: getExecutablePath doesn't return absolute path on OpenBSD (and maybe other OS also) -------------------------------------+------------------------------------- Reporter: oherrala | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: | Version: 8.0.1 libraries/base | Keywords: | Operating System: OpenBSD Architecture: | Type of failure: Incorrect result Unknown/Multiple | at runtime Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- System.Environment.getExecutablePath doesn't return absolute path to executable in OpenBSD. This happens because getExecutablePath uses argv[0] to determine path and argv[0] might not be absolute path. My environment: {{{ $ uname -a OpenBSD fizbuz.pilkki.ciz.fi 6.0 GENERIC.MP#2274 amd64 $ ghc -V The Glorious Glasgow Haskell Compilation System, version 7.10.3 }}} This test program in OpenBSD: {{{#!hs module Main where import System.Environment main = getExecutablePath >>= print }}} returns {{{ $ ./test "./test" }}} For example in OS X the call returns absolute path: {{{ $ ./test "/Users/oherrala/tmp/test" }}} OpenBSD is one of the operating systems which gets fall back to using argv[0] to determine exec's location: https://git.haskell.org/ghc.git/blob/HEAD:/libraries/base/System/Environment... Maybe the argv[0] result should be wrapped with realpath(3) to get absolute path? This bug is also present in cabal-install and reported here: https://github.com/haskell/cabal/issues/3512#issuecomment-231604356 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12377 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12377: getExecutablePath doesn't return absolute path on OpenBSD (and maybe other OS also) -------------------------------------+------------------------------------- Reporter: oherrala | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 7.10.3 Resolution: | Keywords: Operating System: OpenBSD | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by oherrala): * version: 8.0.1 => 7.10.3 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12377#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12377: getExecutablePath doesn't return absolute path on OpenBSD (and maybe other OS also) -------------------------------------+------------------------------------- Reporter: oherrala | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 7.10.3 Resolution: | Keywords: Operating System: OpenBSD | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by thomie): Please send a patch, see [wiki:WorkingConventions/FixingBugs]. I don't think any of the regular contributors use OpenBSD. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12377#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12377: getExecutablePath doesn't return absolute path on OpenBSD (and maybe other OS also) -------------------------------------+------------------------------------- Reporter: oherrala | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 7.10.3 Resolution: | Keywords: Operating System: OpenBSD | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2423 Wiki Page: | -------------------------------------+------------------------------------- Changes (by oherrala): * differential: => Phab:D2423 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12377#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12377: getExecutablePath doesn't return absolute path on OpenBSD (and maybe other OS also) -------------------------------------+------------------------------------- Reporter: oherrala | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 7.10.3 Resolution: | Keywords: Operating System: OpenBSD | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D2423 Wiki Page: | -------------------------------------+------------------------------------- Comment (by hvr): The bug reported in `cabal-install` was fixed wrongly and actually made things worse. Using `realpath(3)` on `argv[0]` is rather unreliable, especially when `argv[0]` doesn't contain any `/`s, it's most certainly wrong to assume that `argv[0]` is relative to the current `$CWD`. See also discussion in Phab:D2423 The problem as I see it, is that `getExecutablePath` claims to provide absolute paths even though it's impossible to do so in a platform independent way (i.e. if all you have to work with is `argv[0]`, which can be set to any arbitrary value by the process invoking `exec(3)`. NB: the `exec(3)`-family requires you to specify the filepath to the executable and the value for `argv[0]` separately, and recommends
The first argument, by convention, should point to the filename associated with the file being executed.
But there's no requirement to do so. I see some options/ways forward: * Change `getExecutablePath`'s type-signature into something like `getExecutable :: Maybe (IO FilePath)` which returns `Nothing` if we don't have any reliable way to report the absolute executable pathname (which should be statically known). (alternatively, for backward compat sake, deprecate `getExecutablePath`, and introduce a new function with the `Maybe`-typesig) * Add support for **reliable** executable path reporting for as many OS as possible (relevant: http://stackoverflow.com/questions/1023306/finding-current- executables-path-without-proc-self-exe ) * Document that `getExecutablePath` only reports a reliable path on Windows/Linux/OSX currently. And everywhere else only returns what `argv[0]` contains. Unfortunately there's no reliable way to figure out at runtime whether `getExecutablePath` returned the real path, or just whatever `argv[0]` said. * Let `getExecutablePath` raise an IO exception of subtype `UnsupportedOperation` if no reliable absolute path can be returned. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12377#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC