Commit 146485d0 authored by Eric Wong's avatar Eric Wong

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
parent 203a5ed2
......@@ -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));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment