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

GHC ghc-devs at haskell.org
Thu Aug 11 06:46:54 UTC 2016


#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


More information about the ghc-tickets mailing list