From f8ce4f1e3af8a14151e711c33c086e5b7429ef95 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Fri, 5 Mar 2021 21:50:28 +0100 Subject: [PATCH] amidi, aseqnet: handle write errors BugLink: https://github.com/alsa-project/alsa-utils/issues/17 Signed-off-by: Jaroslav Kysela --- amidi/amidi.c | 7 +++++-- seq/aseqnet/aseqnet.c | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/amidi/amidi.c b/amidi/amidi.c index cde4697..90e7750 100644 --- a/amidi/amidi.c +++ b/amidi/amidi.c @@ -688,8 +688,11 @@ int main(int argc, char *argv[]) continue; read += length; - if (receive_file != -1) - write(receive_file, buf, length); + if (receive_file != -1) { + ssize_t wlength = write(receive_file, buf, length); + if (wlength != length) + error("write error: %s", wlength < 0 ? strerror(errno) : "short"); + } if (dump) { for (i = 0; i < length; ++i) print_byte(buf[i]); diff --git a/seq/aseqnet/aseqnet.c b/seq/aseqnet/aseqnet.c index 70a1cfd..ebdea0b 100644 --- a/seq/aseqnet/aseqnet.c +++ b/seq/aseqnet/aseqnet.c @@ -491,8 +491,11 @@ static void flush_writebuf(void) if (cur_wrlen) { int i; for (i = 0; i < max_connection; i++) { - if (netfd[i] >= 0) - write(netfd[i], writebuf, cur_wrlen); + if (netfd[i] >= 0) { + ssize_t wrlen = write(netfd[i], writebuf, cur_wrlen); + if (wrlen != (ssize_t)cur_wrlen) + fprintf(stderr, "write error: %s", wrlen < 0 ? strerror(errno) : "short"); + } } cur_wrlen = 0; }