diff options
author | Jeremy Huddleston Sequoia <jeremyhu@apple.com> | 2013-12-07 01:14:37 -0800 |
---|---|---|
committer | Jeremy Huddleston Sequoia <jeremyhu@apple.com> | 2013-12-12 01:30:04 -0800 |
commit | ad8111d7c971ce448905c733d65ba0cfc72bdca4 (patch) | |
tree | 20817f24699bbb49a59e7447864b0cd2a3bb71a0 /os | |
parent | fe07ec19e212a68076560d243a2a935c54589068 (diff) |
darwin: Don't leave stdin/stdout closed
<rdar://problem/15609419>
Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
Diffstat (limited to 'os')
-rw-r--r-- | os/osinit.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/os/osinit.c b/os/osinit.c index 60d10694b..4d48ea94e 100644 --- a/os/osinit.c +++ b/os/osinit.c @@ -213,10 +213,18 @@ OsInit(void) dlinfo(RTLD_SELF, RTLD_DI_SETSIGNAL, &failure_signal); #endif -#if !defined(__CYGWIN__) +#if !defined(XQUARTZ) /* STDIN is already /dev/null and STDOUT/STDERR is managed by console_redirect.c */ +# if defined(__APPLE__) + int devnullfd = open(devnull, O_RDWR, 0); + assert(devnullfd > 2); + + dup2(devnullfd, STDIN_FILENO); + dup2(devnullfd, STDOUT_FILENO); + close(devnullfd); +# elif !defined(__CYGWIN__) fclose(stdin); fclose(stdout); -#endif +# endif /* * If a write of zero bytes to stderr returns non-zero, i.e. -1, * then writing to stderr failed, and we'll write somewhere else @@ -250,6 +258,7 @@ OsInit(void) setlinebuf(stderr); #endif } +#endif /* !XQUARTZ */ #if !defined(WIN32) || defined(__CYGWIN__) if (getpgrp() == 0) |