Skip to content

Commit

Permalink
Make foreign imports of realpath and utimensat safe
Browse files Browse the repository at this point in the history
Although these functions never return EINTR, signals may still affect
these calls.  In particular, realpath on Mac OS X contains a
retry-if-interrupted loop on statfs64.  If the file system is slow
(e.g. SSHFS), the call will hang due to the barrage of periodic alarm
signals from the GHC runtime.  Marking the foreign import as safe
appears to silence the alarm signals.

We also do this for utimensat as a precautionary measure.  Given that
these are system calls that manipulate the file system, the performance
overhead should be negligible.

Fixes haskell#35.
  • Loading branch information
Rufflewind committed Sep 2, 2015
1 parent 2f0c937 commit 389402a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion System/Directory/Internal/C_utimensat.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ toCTimeSpec t = CTimeSpec (CTime sec) (truncate $ 10 ^ (9 :: Int) * frac)
(sec, frac) = if frac' < 0 then (sec' - 1, frac' + 1) else (sec', frac')
(sec', frac') = properFraction (toRational t)

foreign import ccall unsafe "utimensat" c_utimensat
foreign import ccall "utimensat" c_utimensat
:: CInt -> CString -> Ptr CTimeSpec -> CInt -> IO CInt

#endif
2 changes: 1 addition & 1 deletion System/Directory/Internal/Posix.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ c_PATH_MAX | c_PATH_MAX' > toInteger maxValue = Nothing
c_PATH_MAX = Nothing
#endif

foreign import ccall unsafe "realpath" c_realpath
foreign import ccall "realpath" c_realpath
:: CString -> CString -> IO CString

withRealpath :: CString -> (CString -> IO a) -> IO a
Expand Down

0 comments on commit 389402a

Please sign in to comment.