diff options
Diffstat (limited to 'xorg-server/os')
-rw-r--r-- | xorg-server/os/osinit.c | 13 | ||||
-rw-r--r-- | xorg-server/os/utils.c | 24 |
2 files changed, 35 insertions, 2 deletions
diff --git a/xorg-server/os/osinit.c b/xorg-server/os/osinit.c index 60d10694b..4d48ea94e 100644 --- a/xorg-server/os/osinit.c +++ b/xorg-server/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) diff --git a/xorg-server/os/utils.c b/xorg-server/os/utils.c index fb20da755..608ee6ab0 100644 --- a/xorg-server/os/utils.c +++ b/xorg-server/os/utils.c @@ -2071,3 +2071,27 @@ FormatUInt64Hex(uint64_t num, char *string) string[len] = '\0'; } + +/* Move a file descriptor out of the way of our select mask; this + * is useful for file descriptors which will never appear in the + * select mask to avoid reducing the number of clients that can + * connect to the server + */ +int +os_move_fd(int fd) +{ + int newfd; + +#ifdef F_DUPFD_CLOEXEC + newfd = fcntl(fd, F_DUPFD_CLOEXEC, MAXCLIENTS); +#else + newfd = fcntl(fd, F_DUPFD, MAXCLIENTS); +#endif + if (newfd < 0) + return fd; +#ifndef F_DUPFD_CLOEXEC + fcntl(newfd, F_SETFD, FD_CLOEXEC); +#endif + close(fd); + return newfd; +} |