[Haskell-cafe] fcntl locks, executeFile and threaded runtime

Donn Cave donn at avvanta.com
Fri Oct 25 15:52:38 UTC 2013


diego souza <dsouza at c0d3.xxx>,

> I'm having problems with executeFile as it seems to clear the advisory
> locks using the threaded runtime.

I'm stumped, and unfortunately can't duplicate it here (no surprise as
I have a different platform and GHC version.)  But in case it helps ...
your fcntl(2) file lock will be lost if your process closes any fd open
on that file.  So if the threaded runtime for some reason were to dup
random fds and then close them, around a fork, that would do it.  You
might be able to pick that up in an strace (or whatever your platform
utility for system call tracing.) But I don't see how executeFile could
make any difference, in that scenario.

	Donn


> Consider the following snippet (a simplification of what I'm doing):
> 
>     import System.IO
>     import Control.Monad
>     import System.Posix.IO
>     import Control.Concurrent
>     import System.Posix.Files
>     import System.Posix.Process
>      
>     main = do
>       let lock = (WriteLock, AbsoluteSeek, 0, 0)
>       fd  <- openFd "/tmp/foobar" ReadWrite (Just stdFileMode) defaultFileFlags {trunc=True}
>       pid <- forkProcess $ do
>         setLock fd lock >> putStrLn "child: ok"
>         executeFile "/usr/bin/sleep" False ["5"] Nothing
>       threadDelay $ 1 * 1000 * 1000
>       setLock fd lock >> putStrLn "parent: fail!"
>       void $ getProcessStatus True False pid
> 
> Then I consistentlty get these results:
> 
> $ ghc -threaded --make test.hs; ./test
> child: ok
> parent: fail!
> 
> $ ghc -rtsopts --make test.hs; ./test
> child: ok
> test: setLock: resource exhausted (Resource temporarily unavailable)
> 
> Any pointers? At first I though it might be an issue with the unix
> package but that doesn't seem to be the case.
> 
> $ ghc-pkg list | grep unix
>     unix-2.6.0.1
> 
> $ ./test +RTS --info
>  [("GHC RTS", "YES")
>  ,("GHC version", "7.6.3")
>  ,("RTS way", "rts_thr")
>  ,("Build platform", "x86_64-unknown-linux")
>  ,("Build architecture", "x86_64")
>  ,("Build OS", "linux")
>  ,("Build vendor", "unknown")
>  ,("Host platform", "x86_64-unknown-linux")
>  ,("Host architecture", "x86_64")
>  ,("Host OS", "linux")
>  ,("Host vendor", "unknown")
>  ,("Target platform", "x86_64-unknown-linux")
>  ,("Target architecture", "x86_64")
>  ,("Target OS", "linux")
>  ,("Target vendor", "unknown")
>  ,("Word size", "64")
>  ,("Compiler unregisterised", "NO")
>  ,("Tables next to code", "YES")
>  ]
> 
> Thanks!
> ~dsouza
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 


More information about the Haskell-Cafe mailing list