From: Mike Brady Date: Fri, 7 Apr 2017 17:33:05 +0000 (+0100) Subject: Improve error reporting if pipe can't be opened or written to. X-Git-Tag: 3.1.s5~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec0bc81bafe04d03e55b3f12735f071011e8f9dd;p=thirdparty%2Fshairport-sync.git Improve error reporting if pipe can't be opened or written to. --- diff --git a/audio_pipe.c b/audio_pipe.c index 22cac672..9b7d75c7 100644 --- a/audio_pipe.c +++ b/audio_pipe.c @@ -42,21 +42,36 @@ static int fd = -1; char *pipename = NULL; +int warned = 0; static void start(int sample_rate, int sample_format) { // this will leave fd as -1 if a reader hasn't been attached fd = open(pipename, O_WRONLY | O_NONBLOCK); + if ((fd<-1) && (warned==0)) { + warn("Error %d opening the pipe named \"%s\".",errno,pipename); + warned = 1; + } } static void play(short buf[], int samples) { // if the file is not open, try to open it. + char errorstring[1024]; if (fd == -1) { fd = open(pipename, O_WRONLY | O_NONBLOCK); } // if it's got a reader, write to it. - if (fd != -1) { - int ignore = non_blocking_write(fd, buf, samples * 4); - } + if (fd > 0) { + int rc = non_blocking_write(fd, buf, samples * 4); + if ((rc<0) && (warned==0)) { + strerror_r(errno,(char*)errorstring,1024); + warn("Error %d writing to the pipe named \"%s\": \"%s\".",errno,pipename,errorstring); + warned = 1; + } + } else if ((fd == -1) && (warned==0)) { + strerror_r(errno,(char*)errorstring,1024); + warn("Error %d opening the pipe named \"%s\": \"%s\".",errno,pipename,errorstring); + warned = 1; + } } static void stop(void) {