From 319790f4f86f595724fb2bd5aa6274d345469010 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 20 Mar 2012 19:23:32 +0100 Subject: * methods/rred.cc: - check return of writev() as gcc recommends * methods/mirror.cc: - check return of chdir() as gcc recommends * apt-pkg/deb/dpkgpm.cc: - check return of write() a gcc recommends * apt-inst/deb/debfile.cc: - check return of chdir() as gcc recommends * apt-inst/deb/dpkgdb.cc: - check return of chdir() as gcc recommends --- methods/rred.cc | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'methods/rred.cc') diff --git a/methods/rred.cc b/methods/rred.cc index 1e352d0e7..38554464d 100644 --- a/methods/rred.cc +++ b/methods/rred.cc @@ -227,6 +227,21 @@ struct EdCommand { char type; }; #define IOV_COUNT 1024 /* Don't really want IOV_MAX since it can be arbitrarily large */ +ssize_t retry_writev(int fd, const struct iovec *iov, int iovcnt) { + ssize_t Res; + errno = 0; + ssize_t i = 0; + do { + Res = writev(fd, iov + i, iovcnt); + if (Res < 0 && errno == EINTR) + continue; + if (Res < 0) + return _error->Errno("writev",_("Write error")); + iovcnt -= Res; + i += Res; + } while (Res > 0 && iovcnt > 0); + return i; +} #endif /*}}}*/ RredMethod::State RredMethod::patchMMap(FileFd &Patch, FileFd &From, /*{{{*/ @@ -377,7 +392,7 @@ RredMethod::State RredMethod::patchMMap(FileFd &Patch, FileFd &From, /*{{{*/ hash->Add((const unsigned char*) begin, input - begin); if(++iov_size == IOV_COUNT) { - writev(out_file.Fd(), iov, IOV_COUNT); + retry_writev(out_file.Fd(), iov, IOV_COUNT); iov_size = 0; } } @@ -402,7 +417,7 @@ RredMethod::State RredMethod::patchMMap(FileFd &Patch, FileFd &From, /*{{{*/ iov[iov_size].iov_len); if(++iov_size == IOV_COUNT) { - writev(out_file.Fd(), iov, IOV_COUNT); + retry_writev(out_file.Fd(), iov, IOV_COUNT); iov_size = 0; } } @@ -417,15 +432,15 @@ RredMethod::State RredMethod::patchMMap(FileFd &Patch, FileFd &From, /*{{{*/ } if(iov_size) { - writev(out_file.Fd(), iov, iov_size); + retry_writev(out_file.Fd(), iov, iov_size); iov_size = 0; } for(i = 0; i < iov_size; i += IOV_COUNT) { if(iov_size - i < IOV_COUNT) - writev(out_file.Fd(), iov + i, iov_size - i); + retry_writev(out_file.Fd(), iov + i, iov_size - i); else - writev(out_file.Fd(), iov + i, IOV_COUNT); + retry_writev(out_file.Fd(), iov + i, IOV_COUNT); } delete [] iov; -- cgit v1.2.3