diff options
author | wtc%netscape.com <devnull@localhost> | 2001-10-18 04:20:34 +0000 |
---|---|---|
committer | wtc%netscape.com <devnull@localhost> | 2001-10-18 04:20:34 +0000 |
commit | fe55e3eeea18abd166440311249a009f731ca640 (patch) | |
tree | 9e12608c25c004b6a125df62ffe502f915563d4b | |
parent | 415661f3132446b3b11a8538996138aa9dee15a7 (diff) | |
download | nspr-hg-fe55e3eeea18abd166440311249a009f731ca640.tar.gz |
Bugzilla bug 77197: use spawn in Neutrino because fork & exec does not
work in multithreaded programs in Neutrino. The patch is contributed
by dinglis@qnx.com (Dave Inglis), reviewed and modified by wtc.
Tag: NSPRPUB_PRE_4_2_CLIENT_BRANCH
-rw-r--r-- | pr/src/md/unix/uxproces.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/pr/src/md/unix/uxproces.c b/pr/src/md/unix/uxproces.c index d7682494..9530cf52 100644 --- a/pr/src/md/unix/uxproces.c +++ b/pr/src/md/unix/uxproces.c @@ -267,6 +267,46 @@ ForkAndExec( #ifdef AIX process->md.pid = (*pr_wp.forkptr)(); +#elif defined(NTO) + /* + * fork() & exec() does not work in a multithreaded process. + * Use spawn() instead. + */ + { + int fd_map[3] = { 0, 1, 2 }; + + if (attr) { + if (attr->stdinFd && attr->stdinFd->secret->md.osfd != 0) { + fd_map[0] = dup(attr->stdinFd->secret->md.osfd); + flags = fcntl(fd_map[0], F_GETFL, 0); + if (flags & O_NONBLOCK) + fcntl(fd_map[0], F_SETFL, flags & ~O_NONBLOCK); + } + if (attr->stdoutFd && attr->stdoutFd->secret->md.osfd != 1) { + fd_map[1] = dup(attr->stdoutFd->secret->md.osfd); + flags = fcntl(fd_map[1], F_GETFL, 0); + if (flags & O_NONBLOCK) + fcntl(fd_map[1], F_SETFL, flags & ~O_NONBLOCK); + } + if (attr->stderrFd && attr->stderrFd->secret->md.osfd != 2) { + fd_map[2] = dup(attr->stderrFd->secret->md.osfd); + flags = fcntl(fd_map[2], F_GETFL, 0); + if (flags & O_NONBLOCK) + fcntl(fd_map[2], F_SETFL, flags & ~O_NONBLOCK); + } + + PR_ASSERT(attr->currentDirectory == NULL); /* not implemented */ + } + + process->md.pid = spawn(path, 3, fd_map, NULL, argv, childEnvp); + + if (fd_map[0] != 0) + close(fd_map[0]); + if (fd_map[1] != 1) + close(fd_map[1]); + if (fd_map[2] != 2) + close(fd_map[2]); + } #else process->md.pid = fork(); #endif @@ -285,6 +325,7 @@ ForkAndExec( * the parent process's standard I/O data structures. */ +#if !defined(NTO) #ifdef VMS /* OpenVMS has already handled all this above */ #else @@ -367,6 +408,7 @@ ForkAndExec( #else _exit(1); #endif /* VMS */ +#endif /* !NTO */ } if (newEnvp) { |