www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13753] New: src/std/process.d: _spawnvp is broken

https://issues.dlang.org/show_bug.cgi?id=13753

          Issue ID: 13753
           Summary: src/std/process.d: _spawnvp is broken
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: Phobos
          Assignee: nobody puremagic.com
          Reporter: danny.milo gmail.com

The _spawnvp in src/std/process.d is broken.

First, if the child process (say it has pid B) fails to execvp, it's a bad idea
to then throw an Exception. The entire point of spawnvp in general is to hide
the fact that the current process A was forked off. But now the Exception
propagates through process B, so certainly the caller will notice that
something is off (the caller is suddenly inside another process than he started
out in). 

Later on, the waitpid result is not checked. It is possible for waitpid to
return (-1). In that case, errno contains the error code and "status" contains
garbage, which is then compared against.

Also, all Posix system calls can return (-1) and errno = EINTR (see
<http://www.jwz.org/doc/worse-is-better.html>, search for "PC loser-ing") to
indicate that while the user process asked for action S to be performed, really
it should be checking and doing some other action T before.

So for the latter there really should be some global delegate that is called on
EINTR which decides whether to do anything about it, possibly terminating the
loop (or not, it depends). 

This is not specific to process.d but all functions that do system calls should
call this. Even std.stdio.File functions should do this.

Also, it throws an Exception (literally that) using strerror_r to build it
instead of just using ErrnoException. Why?

--
Nov 19 2014