diff options
author | Eric Wong <normalperson@yhbt.net> | 2007-09-04 19:45:24 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2007-09-04 19:45:24 +0000 |
commit | 146485d0cb65004c9dc5ebbf9ea981a82b9343d4 (patch) | |
tree | 292a22d9050d34d689d95bc317c75ed3c8e265af | |
parent | 203a5ed26d8d955dbe0490b35274571269751d8c (diff) | |
download | mpd-146485d0cb65004c9dc5ebbf9ea981a82b9343d4.tar.gz mpd-146485d0cb65004c9dc5ebbf9ea981a82b9343d4.tar.xz mpd-146485d0cb65004c9dc5ebbf9ea981a82b9343d4.zip |
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
Diffstat (limited to '')
-rw-r--r-- | src/log.c | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -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)); |