aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2008-01-26 22:16:39 +0000
committerEric Wong <normalperson@yhbt.net>2008-01-26 22:16:39 +0000
commit4c16b2a4fbb11803c29e0686873589af8262dfbb (patch)
tree881c84b29521e82fcee86e32ac6c391b9e4d7b62
parent1d30ef6257897a8dc78ebe831c8e10834054f348 (diff)
downloadmpd-4c16b2a4fbb11803c29e0686873589af8262dfbb.tar.gz
mpd-4c16b2a4fbb11803c29e0686873589af8262dfbb.tar.xz
mpd-4c16b2a4fbb11803c29e0686873589af8262dfbb.zip
Fix endless loop when mpd is launched from a non-interactive shell.
Thanks to _noth_ for the patch, this fixes Mantis bug #1534 _noth_ wrote: > When MPD is launched from a non-interactive shell, it enters an endless > loop, filling up its error log file with "error accept()'ing" messages. > This is caused by the fact that stdin is already closed when mpd starts > up. listenOnPort() opens up the first of its sockets as fd 0 (the first > empty fd table position). Then, setup_log_output()->redirect_stdin() > overwrites fd0 (fd=open("/dev/null",...); dup2(fd, STDIN_FILENO);) > without checking if it corresponds to the actual standard input (or if > it is open in the first place). This means that listenSockets[0].fd now > is a fd for /dev/null, thus doIOForInterfaces()->getConnections() can't > accept(2) on it and fails with the above error. The attached patch fixes > this for me. r6843 in trunk git-svn-id: https://svn.musicpd.org/mpd/branches/branch-0.13.0-fixes@7159 09075e82-0dd4-0310-85a5-a0d7c8717e4f
-rw-r--r--src/log.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/log.c b/src/log.c
index fa4ae64f0..974c07146 100644
--- a/src/log.c
+++ b/src/log.c
@@ -40,7 +40,11 @@ static const char *err_filename;
/* redirect stdin to /dev/null to work around a libao bug */
static void redirect_stdin(void)
{
- int fd;
+ int fd, st;
+ struct stat ss;
+
+ if ((st = fstat(STDIN_FILENO, &ss)) < 0 || ! 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)