[PATCH 1/1] darwin: Don't leave stdin/stdout closed

Jeremy Huddleston Sequoia jeremyhu at apple.com
Sat Dec 7 01:31:40 PST 2013


As I'm sure other platforms would get cranky if stdin or stdout are closed, is there interest in just using this approach for the !defined(__CYGWIN__) case instead of just on darwin?

On Dec 7, 2013, at 01:26, Jeremy Huddleston Sequoia <jeremyhu at apple.com> wrote:

> <rdar://problem/15609419>
> 
> Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
> ---
> os/osinit.c | 13 +++++++++++--
> 1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/os/osinit.c b/os/osinit.c
> index 60d1069..4d48ea9 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)
> -- 
> 1.8.4.3
> 
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4136 bytes
Desc: not available
URL: <http://lists.x.org/archives/xorg-devel/attachments/20131207/6a9e323d/attachment.bin>


More information about the xorg-devel mailing list