From: Matt McCutchen Date: Sat, 31 Jan 2009 06:14:17 +0000 (-0500) Subject: Give a meaningful error message when we fail to write to a batch file. X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/commitdiff_plain/f8605c5b89720a09b8aa0d5e7aa3ea27b1ebbf4f Give a meaningful error message when we fail to write to a batch file. --- diff --git a/io.c b/io.c index 5f70e819..6a89c8fa 100644 --- a/io.c +++ b/io.c @@ -1423,6 +1423,22 @@ static void sleep_for_bwlimit(int bytes_written) total_written = (sleep_usec - elapsed_usec) * bwlimit / (ONE_SEC/1024); } +static const char *what_fd_is(int fd) +{ + static char buf[20]; + + if (fd == sock_f_out) + return "socket"; + else if (fd == msg_fd_out) + return "message fd"; + else if (fd == batch_fd) + return "batch file"; + else { + snprintf(buf, sizeof buf, "fd %d", fd); + return buf; + } +} + /* Write len bytes to the file descriptor fd, looping as necessary to get * the job done and also (in certain circumstances) reading any data on * msg_fd_in to avoid deadlock. @@ -1501,8 +1517,8 @@ static void writefd_unbuffered(int fd, const char *buf, size_t len) if (am_server && fd == msg_fd_out) exit_cleanup(RERR_STREAMIO); rsyserr(FERROR, errno, - "writefd_unbuffered failed to write %ld bytes [%s]", - (long)len, who_am_i()); + "writefd_unbuffered failed to write %ld bytes to %s [%s]", + (long)len, what_fd_is(fd), who_am_i()); /* If the other side is sending us error messages, try * to grab any messages they sent before they died. */ while (!am_server && fd == sock_f_out && io_multiplexing_in) { @@ -1560,10 +1576,8 @@ static void writefd(int fd, const char *buf, size_t len) if (fd == sock_f_out) stats.total_written += len; - if (fd == write_batch_monitor_out) { - if ((size_t)write(batch_fd, buf, len) != len) - exit_cleanup(RERR_FILEIO); - } + if (fd == write_batch_monitor_out) + writefd_unbuffered(batch_fd, buf, len); if (!iobuf_out || fd != iobuf_f_out) { writefd_unbuffered(fd, buf, len);