This fixes a problem where ogg123 takes 100% of the cpu and is unable to be stopped with anything less than 'kill -9' when outputting to a pipe which closes. My test is: ./ogg123 -d wav -f - test.ogg | less then press q to quit less. Ogg123 will hang and start taking 100% of the CPU. Index: ogg123/buffer.c =================================================================== --- ogg123.orig/buffer.c 2008-05-01 19:21:12.000000000 -0700 +++ ogg123/buffer.c 2008-05-01 19:32:16.000000000 -0700 @@ -207,7 +207,7 @@ /* This test is safe since curfill will never decrease and eos will never be unset. */ - while ( !(buf->eos && buf->curfill == 0)) { + while ( !(buf->eos && buf->curfill == 0) && !buf->abort_write) { if (buf->cancel_flag || sig_request.cancel) break; @@ -251,6 +251,11 @@ write_amount == buf->curfill ? buf->eos : 0, buf->write_arg); + if (!write_amount) { + DEBUG("Error writing to the audio device. Aborting."); + buffer_abort_write(buf); + } + LOCK_MUTEX(buf->mutex); buf->curfill -= write_amount; @@ -746,7 +751,7 @@ pthread_cleanup_push(buffer_mutex_unlock, buf); LOCK_MUTEX(buf->mutex); - while (!empty) { + while (!empty && !buf->abort_write) { if (buf->curfill > 0) { DEBUG1("Buffer curfill = %ld, going back to sleep.", buf->curfill);