diff options
Diffstat (limited to 'src/listen.c')
-rw-r--r-- | src/listen.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/listen.c b/src/listen.c index 323bf430f..da8482e4e 100644 --- a/src/listen.c +++ b/src/listen.c @@ -50,6 +50,34 @@ static int *listenSockets; static int numberOfListenSockets; static int boundPort; +/* + * redirect stdin to /dev/null to work around a libao bug + * there are likely other bugs in other libraries (and even our code!) + * that check for fd > 0, so it's easiest to just keep + * fd = 0 == /dev/null for now... + */ +static void redirect_stdin(void) +{ + int fd, st; + struct stat ss; + + if ((st = fstat(STDIN_FILENO, &ss)) < 0) { + if ((fd = open("/dev/null", O_RDONLY) > 0)) { + DEBUG("stdin closed, and could not open /dev/null " + "as fd=0, some external library bugs " + "may be exposed...\n"); + close(fd); + } + return; + } + if (!isatty(STDIN_FILENO)) + return; + if ((fd = open("/dev/null", O_RDONLY)) < 0) + FATAL("failed to open /dev/null %s\n", strerror(errno)); + if (dup2(fd, STDIN_FILENO) < 0) + FATAL("dup2 stdin: %s\n", strerror(errno)); +} + static int establishListen(unsigned int port, struct sockaddr *addrp, socklen_t addrlen) { @@ -196,6 +224,7 @@ void listenOnPort(void) boundPort = port; + redirect_stdin(); do { parseListenConfigParam(port, param); } while ((param = getNextConfigParam(CONF_BIND_TO_ADDRESS, param))); |