Improve runInteractiveProcess error message when working directory does not exist
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.
Trac metadata
Trac field | Value |
---|---|
Version | 6.7 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | libraries (other) |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | marig1@wp.pl, tomasz.zielonka@gmail.com |
Operating system | Unknown |
Architecture | Unknown |