#1593: runInteractiveProcess misbehaves when it gets invalid (eg. non-existent)
working directory parameter
----------------------------------------+-----------------------------------
  Reporter:  [EMAIL PROTECTED]  |          Owner:         
      Type:  bug                        |         Status:  new    
  Priority:  normal                     |      Milestone:         
 Component:  libraries (other)          |        Version:  6.7    
  Severity:  normal                     |       Keywords:         
Difficulty:  Unknown                    |             Os:  Unknown
  Testcase:                             |   Architecture:  Unknown
----------------------------------------+-----------------------------------
Example code:

 {{{
   import System.Process

   main = do
       (_, _, _, commhand) <-
           runInteractiveProcess "echo" ["something"] (Just "/no/such/dir")
 Nothing
       exitCode <- waitForProcess commhand
       print exitCode
 }}}

 This happens on Linux with both 6.6 and the latest HEAD snapshot.

 I think the problem is in C code, in libraries/base/cbits/runProcess.c
 (6.6).
 Below are the important code fragments. Search for BUG HERE for a bug
 location.

 {{{
 ProcHandle
 runInteractiveProcess (char *const args[],
                char *workingDirectory, char **environment,
                int *pfdStdInput, int *pfdStdOutput, int *pfdStdError)
 {
     ...

     switch(pid = fork())
     {
     ...

     case 0:
     {
         pPrPr_disableITimers();

         if (workingDirectory) {
             if (chdir (workingDirectory) < 0) {
                 // BUG HERE:
                 // Calling return here is bad idea here. This code
                 // is run in the child process and returning makes the
                 // child act as if it was the parent - strange things will
                 // happen!
                 return -1;
             }
         }

         ...

         /* the child */
         if (environment) {
             execvpe(args[0], args, environment);
         } else {
             execvp(args[0], args);
         }
     }
     _exit(127);

     default:
     ...
 }}}

 I thought about sending a patch, but I'm not sure what the fix should be.
 Doing "_exit(SOMETHING)" instead of return seems to be better then
 returning, but I don't know what SOMETHING should be, and maybe there is a
 better solution.

 I think I've seen the same problem in another run*Process function in this
 C file.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1593>
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