Skip to content

getExecutablePath adds " (deleted)" suffix if executable was deleted under linux

If we remove current executable or update it with a new one, getExecutablePath returns path with added " (deleted)" suffix. I think it is incorrect behavior , for example if you updated binary and want to exec a new one, the obvious way to go is to call getExecutablePath and use it. Moreover it is inconsistent between platforms. Problem stems from the fact the getExecutablePath is implemented as readlink on /proc/self/exe and it contains gibberish once file has been deleted.

Example:

module Main (main) where

import System.Environment (getExecutablePath)
import System.Directory (removeFile)

main :: IO ()
main = do
  before <- getExecutablePath
  putStrLn $ "Before: " ++ before
  removeFile before
  after <- getExecutablePath
  putStrLn $ "After:  " ++ after

Output:

$ ./getExecutablePath 
Before: /mnt/data/Maggot/getExecutablePath
After:  /mnt/data/Maggot/getExecutablePath (deleted)
Trac metadata
Trac field Value
Version 7.10.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Core Libraries
Test case
Differential revisions
BlockedBy
Related
Blocking
CC aslpavel, ekmett
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information