Skip to content
Snippets Groups Projects
Unverified Commit e8a2fbcd authored by Michael Snoyman's avatar Michael Snoyman Committed by GitHub
Browse files

Merge pull request #285 from haskell/wip/T284

Address #284 and #283
parents c956562f c25afa93
No related branches found
No related tags found
No related merge requests found
...@@ -107,23 +107,17 @@ setup_std_handle_fork(int fd, ...@@ -107,23 +107,17 @@ setup_std_handle_fork(int fd,
* errors. See #266. * errors. See #266.
*/ */
int unshadow_pipe_fd(int fd, char **failed_doing) { int unshadow_pipe_fd(int fd, char **failed_doing) {
int i = 0; if (fd > 2) {
int fds[3] = {0}; return fd;
for (i = 0; fd < 3 && i < 3; ++i) { }
fds[i] = fd;
fd = dup(fd); int new_fd = fcntl(fd, F_DUPFD, 3);
if (fd == -1) { if (new_fd == -1) {
*failed_doing = "dup(unshadow)"; *failed_doing = "fcntl(F_DUP_FD)";
return -1; return -1;
} }
} close(fd);
for (int j = 0; j < i; ++j) { return new_fd;
if (close(fds[j]) == -1) {
*failed_doing = "close(unshadow)";
return -1;
}
}
return fd;
} }
/* Try spawning with fork. */ /* Try spawning with fork. */
...@@ -154,17 +148,6 @@ do_spawn_fork (char *const args[], ...@@ -154,17 +148,6 @@ do_spawn_fork (char *const args[],
return -1; return -1;
} }
// Block signals with Haskell handlers. The danger here is that
// with the threaded RTS, a signal arrives in the child process,
// the RTS writes the signal information into the pipe (which is
// shared between parent and child), and the parent behaves as if
// the signal had been raised.
blockUserSignals();
// See #4074. Sometimes fork() gets interrupted by the timer
// signal and keeps restarting indefinitely.
stopTimer();
// N.B. execvpe is not supposed on some platforms. In this case // N.B. execvpe is not supposed on some platforms. In this case
// we emulate this using fork and exec. However, to safely do so // we emulate this using fork and exec. However, to safely do so
// we need to perform all allocations *prior* to forking. Consequently, we // we need to perform all allocations *prior* to forking. Consequently, we
...@@ -181,6 +164,17 @@ do_spawn_fork (char *const args[], ...@@ -181,6 +164,17 @@ do_spawn_fork (char *const args[],
} }
#endif #endif
// Block signals with Haskell handlers. The danger here is that
// with the threaded RTS, a signal arrives in the child process,
// the RTS writes the signal information into the pipe (which is
// shared between parent and child), and the parent behaves as if
// the signal had been raised.
blockUserSignals();
// See #4074. Sometimes fork() gets interrupted by the timer
// signal and keeps restarting indefinitely.
stopTimer();
int pid = fork(); int pid = fork();
switch(pid) switch(pid)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment