#3231: Permission denied error with runProcess/openFile
--------------------------+-------------------------------------------------
 Reporter:  NeilMitchell  |          Owner:                  
     Type:  bug           |         Status:  new             
 Priority:  normal        |      Milestone:                  
Component:  Compiler      |        Version:  6.10.2          
 Severity:  normal        |     Resolution:                  
 Keywords:                |       Testcase:                  
       Os:  Windows       |   Architecture:  Unknown/Multiple
--------------------------+-------------------------------------------------
Comment (by claus):

 Thanks for bringing this from rumour to concrete code. Sounded like a good
 example to try out ProcessExplorer on!-) I tried the following variation,
 to give me some control and time to see the open handles:
 {{{
 module Main() where

 import Control.Concurrent
 import System.IO
 import System.Directory
 import System.Process
 import Control.Exception(bracket)

 my_system str = do
   (_,_,_,p) <- createProcess c
   waitForProcess p
   where c = CreateProcess { cmdspec = ShellCommand str,
                             cwd = Nothing,
                             env = Nothing,
                             std_in = Inherit,
                             std_out = Inherit,
                             std_err = Inherit,
                             close_fds = True }

 main = do
    v <- newEmptyMVar
    hSetBuffering stdout NoBuffering
    forkIO $ f v "foo1.txt"
    forkIO $ f v "foo2.txt"
    threadDelay $ 100*1000000
    putStrLn "Finished successfully"

 f v file = do
    bracket (openFile file WriteMode)
            (hClose)
            (\h->do hPutStrLn h file
                    hPutStr stderr (">"++file++"< ")
                    my_system "sleep 5s"
            )
    -- takeMVar v
    hPutStr stderr ("<"++file++"> ")
    my_system "sleep 5s"
    removeFile file
    f v file
 }}}
 It seems that no matter what I set `close_fds` to (default `False`?), both
 GHC and one of its two children sometimes hang on to both files, while the
 other child hangs on to `foo1` only?? Also, there is occasionally a new
 pair of children, before the old pair is gone (this tends to preceed the
 access error). Are these just ProcessExplorer sampling artifacts, am I
 misreading the data, or is there something else going on (ghc
 6.11.20090320)?

 Btw, after Duncan's remark, I looked up [http://msdn.microsoft.com/en-
 us/library/aa363915(VS.85).aspx DeleteFile] and found these two -seemingly
 contradictory- remarks:

  The DeleteFile function fails if an application attempts to delete a file
 that is open for normal I/O or as a memory-mapped file.

  The DeleteFile function marks a file for deletion on close. Therefore,
 the file deletion does not occur until the last handle to the file is
 closed. Subsequent calls to CreateFile to open the file fail with
 ERROR_ACCESS_DENIED.

 Could anyone please explain what that second remark means, given the
 first? What is the non-normal I/O it seems to apply to?

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3231#comment:8>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to