From 146485d0cb65004c9dc5ebbf9ea981a82b9343d4 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 4 Sep 2007 19:45:24 +0000 Subject: log: better bug avoidance for libraries incorrectly handling fd=0 We redirect stdin to /dev/null to work around a libao bug, but this bug has been fixed in libao since 2003 (according to jat). However, there are likely other bugs in other libraries (and even our code!) that handle fd=0 incorrectly and I'd rather not take the risk[1]. So So it's easiest to just keep fd=0==/dev/null for now... [1] - I've seen several of these myself... git-svn-id: https://svn.musicpd.org/mpd/trunk@6849 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/log.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/log.c b/src/log.c index 1405ba301..e654d1941 100644 --- a/src/log.c +++ b/src/log.c @@ -39,13 +39,27 @@ static int err_fd = -1; static const char *out_filename; static const char *err_filename; -/* redirect stdin to /dev/null to work around a libao bug */ +/* + * 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 || ! isatty(STDIN_FILENO)) + 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)); -- cgit v1.2.3