Opened 10 years ago

Closed 5 years ago

Last modified 4 years ago

#3649 closed bug (fixed)

inconsistent exception between unix/windows for running non-existant program

Reported by: duncan Owned by: snoyberg
Priority: low Milestone: 8.0.1
Component: Core Libraries Version: 6.10.4
Keywords: Cc: core-libraries-committee@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

handle (print . isDoesNotExistError) $ do
  (_,_,_,hnd) <- createProcess (proc "foobar" [])
  print =<< waitForProcess hnd

On Windows this prints True since it throws a "does not exists" kind of IOException. On Unix instead the createProcess call succeeds and then waiting on the process claims it terminated with an exit code of 127.

It is annoying that we need two different error handling mechanisms in this case. For example Cabal wants to know when it tries to run a program that cannot be found (eg when it tries to run sh.exe on Windows).

It would be better if the behaviour was consistent. The behaviour on Windows seems to be the more sensible one. We should be able to make the Unix behaviour the same since the exceve call does indeed return an error code when loading the new executable image fails.

Change History (16)

comment:1 Changed 10 years ago by igloo

Milestone: 6.14.1
Type of failure: None/Unknown

comment:2 Changed 9 years ago by duncan

Another instance of the same problem is when we do not have permission to execute the program (see ticket #4110 where the original example is about /tmp being mounted "noexec").

comment:3 Changed 9 years ago by igloo

Milestone: 7.0.17.0.2

comment:4 Changed 9 years ago by igloo

Milestone: 7.0.27.2.1

comment:5 Changed 8 years ago by igloo

Milestone: 7.2.17.4.1

comment:6 Changed 8 years ago by igloo

Milestone: 7.4.17.6.1
Priority: normallow

comment:7 Changed 7 years ago by igloo

Milestone: 7.6.17.6.2

comment:8 Changed 6 years ago by benmachine

difficulty: Unknown

Since Ian's changes to libraries/process in commit df810a59d84703ca7ad548f29f635bda6f48b493 , is this fixed?

comment:9 Changed 6 years ago by igloo

Resolution: fixed
Status: newclosed

Looks like it; this now prints True on Linux:

import Control.Exception
import System.IO.Error
import System.Process

main = handle (print . isDoesNotExistError) $ do
          (_,_,_,hnd) <- createProcess (proc "foobar" [])
          print =<< waitForProcess hnd

Thanks for pointing it out, benmachine!

comment:10 Changed 6 years ago by duncan

Resolution: fixed
Status: closednew

Note that the C code still says (roughly):

        if (close_fds) {
            int i;
            // XXX Not the pipe
            for (i = 3; i < max_fd; i++) {
                close(i);
            }
        }

Which means that this nice new error handling will (I think) go wrong in the CreateProcess { close_fds = True } case. Should be easy to fix, just something like...

            for (i = 3; i < max_fd; i++) {
                if (i != forkCommunicationFds[1]) { close(i); }
            }

comment:11 Changed 5 years ago by thoughtpolice

Milestone: 7.6.27.10.1

Moving to 7.10.1.

comment:12 Changed 5 years ago by thoughtpolice

Component: libraries/processCore Libraries
Owner: set to ekmett

Moving over to new owning component 'Core Libraries'.

comment:13 Changed 5 years ago by thoughtpolice

Milestone: 7.10.17.12.1

Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:14 Changed 5 years ago by snoyberg

Cc: core-libraries-committee@… added
Owner: changed from ekmett to snoyberg

comment:15 Changed 5 years ago by snoyberg

Resolution: fixed
Status: newclosed

Duncan, I've implemented a fix for this at: https://github.com/snoyberg/process/commit/2fe95e32adff6d03cd04e3cf0f6d99f66625b33c. I'm going to close this issue as resolved, if there is still a problem please reopen.

comment:16 Changed 4 years ago by thoughtpolice

Milestone: 7.12.18.0.1

Milestone renamed

Note: See TracTickets for help on using tickets.