sndio: Fix segmentation fault when audio card is removed

This can happen if you remove an external audio card or if you stop
sndiod(8) while playing a song.

sio_write() will retry internally if it fails with errno == EINTR
so no need to handle that.
This commit is contained in:
Dimitris Papastamos 2016-06-22 14:33:55 +01:00 committed by Max Kellermann
parent cb1082c58c
commit d4f801a8e9
1 changed files with 5 additions and 6 deletions

View File

@ -17,7 +17,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <errno.h>
#include <sndio.h>
#include <string.h>
#include <unistd.h>
@ -183,11 +182,11 @@ SndioOutput::Play(const void *chunk, size_t size, Error &error)
while (1) {
n = sio_write(sio_hdl, chunk, size);
if (n < 0) {
if (errno == EINTR)
continue;
error.FormatErrno("Failed to write %zu bytes to sndio output", size);
return 0;
if (n == 0) {
if (sio_eof(sio_hdl)) {
error.Set(sndio_output_domain, -1, "sndio write failed");
return 0;
}
}
return n;
}