--- linuxthreads/pthread.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) --- a/linuxthreads/pthread.c +++ b/linuxthreads/pthread.c @@ -662,6 +662,29 @@ free(__pthread_manager_thread_bos); return -1; } + /* Make sure the file descriptors of the pipe doesn't collide + with stdin, stdout or stderr if they have been closed. */ + if (manager_pipe[0] < 3) { + int new_fd; + new_fd = fcntl(manager_pipe[0], F_DUPFD, 3); + close(manager_pipe[0]); + if (new_fd == -1) { + free(__pthread_manager_thread_bos); + return -1; + } + manager_pipe[0] = new_fd; + } + if (manager_pipe[1] < 3) { + int new_fd; + new_fd = fcntl(manager_pipe[1], F_DUPFD, 3); + close(manager_pipe[1]); + if (new_fd == -1) { + close(manager_pipe[0]); + free(__pthread_manager_thread_bos); + return -1; + } + manager_pipe[1] = new_fd; + } #ifdef USE_TLS /* Allocate memory for the thread descriptor and the dtv. */