diff options
author | David Kalnischkies <kalnischkies@gmail.com> | 2012-03-20 19:23:32 +0100 |
---|---|---|
committer | David Kalnischkies <kalnischkies@gmail.com> | 2012-03-20 19:23:32 +0100 |
commit | 319790f4f86f595724fb2bd5aa6274d345469010 (patch) | |
tree | 0c2686423a217f557fbdd990111d6947a5d228e7 | |
parent | 571449d4444a8a6f5c55dce318cdf16805c04743 (diff) | |
download | apt-319790f4f86f595724fb2bd5aa6274d345469010.tar.gz |
* 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
-rw-r--r-- | apt-inst/deb/debfile.cc | 2 | ||||
-rw-r--r-- | apt-inst/deb/dpkgdb.cc | 3 | ||||
-rw-r--r-- | apt-pkg/deb/dpkgpm.cc | 36 | ||||
-rw-r--r-- | debian/changelog | 12 | ||||
-rw-r--r-- | methods/mirror.cc | 5 | ||||
-rw-r--r-- | methods/rred.cc | 25 |
6 files changed, 64 insertions, 19 deletions
diff --git a/apt-inst/deb/debfile.cc b/apt-inst/deb/debfile.cc index 4bd065cf8..aeab82e82 100644 --- a/apt-inst/deb/debfile.cc +++ b/apt-inst/deb/debfile.cc @@ -121,7 +121,7 @@ bool debDebFile::ExtractControl(pkgDataBase &DB) // Switch out of the tmp directory. if (chdir(Cwd.c_str()) != 0) - chdir("/"); + return _error->Errno("chdir",_("Unable to change to %s"),Cwd.c_str()); return true; } diff --git a/apt-inst/deb/dpkgdb.cc b/apt-inst/deb/dpkgdb.cc index 819c123f6..71a0c2177 100644 --- a/apt-inst/deb/dpkgdb.cc +++ b/apt-inst/deb/dpkgdb.cc @@ -286,8 +286,7 @@ bool debDpkgDB::ReadFList(OpProgress &Progress) delete [] Buffer; if (chdir(Cwd.c_str()) != 0) - chdir("/"); - + return _error->Errno("chdir",_("Unable to change to %s"),Cwd.c_str()); return !_error->PendingError(); } /*}}}*/ diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index c46a81209..63c5a6380 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -163,6 +163,25 @@ pkgCache::VerIterator FindNowVersion(const pkgCache::PkgIterator &Pkg) return Ver; } /*}}}*/ +ssize_t retry_write(int fd, const void *buf, size_t count) +{ + int Res; + ssize_t i = 0; + errno = 0; + do + { + Res = write(fd, buf, count); + if (Res < 0 && errno == EINTR) + continue; + if (Res < 0) + break; + buf = (char *)buf + Res; + count -= Res; + i += Res; + } + while (Res > 0 && count > 0); + return i; +} // DPkgPM::pkgDPkgPM - Constructor /*{{{*/ // --------------------------------------------------------------------- @@ -425,7 +444,7 @@ void pkgDPkgPM::DoStdin(int master) unsigned char input_buf[256] = {0,}; ssize_t len = read(0, input_buf, sizeof(input_buf)); if (len) - write(master, input_buf, len); + retry_write(master, input_buf, len); else d->stdin_is_dev_null = true; } @@ -451,7 +470,7 @@ void pkgDPkgPM::DoTerminalPty(int master) } if(len <= 0) return; - write(1, term_buf, len); + retry_write(1, term_buf, len); if(d->term_out) fwrite(term_buf, len, sizeof(char), d->term_out); } @@ -526,7 +545,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line) << ":" << s << endl; if(OutStatusFd > 0) - write(OutStatusFd, status.str().c_str(), status.str().size()); + retry_write(OutStatusFd, status.str().c_str(), status.str().size()); if (Debug == true) std::clog << "send: '" << status.str() << "'" << endl; @@ -550,7 +569,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line) << ":" << list[3] << endl; if(OutStatusFd > 0) - write(OutStatusFd, status.str().c_str(), status.str().size()); + retry_write(OutStatusFd, status.str().c_str(), status.str().size()); if (Debug == true) std::clog << "send: '" << status.str() << "'" << endl; pkgFailures++; @@ -564,7 +583,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line) << ":" << list[3] << endl; if(OutStatusFd > 0) - write(OutStatusFd, status.str().c_str(), status.str().size()); + retry_write(OutStatusFd, status.str().c_str(), status.str().size()); if (Debug == true) std::clog << "send: '" << status.str() << "'" << endl; return; @@ -592,7 +611,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line) << ":" << s << endl; if(OutStatusFd > 0) - write(OutStatusFd, status.str().c_str(), status.str().size()); + retry_write(OutStatusFd, status.str().c_str(), status.str().size()); if (Debug == true) std::clog << "send: '" << status.str() << "'" << endl; } @@ -1055,7 +1074,8 @@ bool pkgDPkgPM::Go(int OutStatusFd) } int fd[2]; - pipe(fd); + if (pipe(fd) != 0) + return _error->Errno("pipe","Failed to create IPC pipe to dpkg"); #define ADDARG(X) Args.push_back(X); Size += strlen(X) #define ADDARGC(X) Args.push_back(X); Size += sizeof(X) - 1 @@ -1236,7 +1256,7 @@ bool pkgDPkgPM::Go(int OutStatusFd) << (PackagesDone/float(PackagesTotal)*100.0) << ":" << _("Running dpkg") << endl; - write(OutStatusFd, status.str().c_str(), status.str().size()); + retry_write(OutStatusFd, status.str().c_str(), status.str().size()); } Child = ExecFork(); diff --git a/debian/changelog b/debian/changelog index 5da87a5ad..bb5d9920a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -21,11 +21,21 @@ apt (0.8.16~exp14) UNRELEASED; urgency=low - check return of chdir() as gcc recommends * apt-pkg/contrib/netrc.cc: - check return of asprintf() as gcc recommends + * 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/makefile: - do not link rred against libz anymore as FileFd handles all this transparently now - -- David Kalnischkies <kalnischkies@gmail.com> Tue, 20 Mar 2012 18:29:33 +0100 + -- David Kalnischkies <kalnischkies@gmail.com> Tue, 20 Mar 2012 19:22:49 +0100 apt (0.8.16~exp13) experimental; urgency=low diff --git a/methods/mirror.cc b/methods/mirror.cc index 3b2ab8ede..eb6d97425 100644 --- a/methods/mirror.cc +++ b/methods/mirror.cc @@ -124,9 +124,10 @@ bool MirrorMethod::Clean(string Dir) if (I == list.end()) unlink(Dir->d_name); }; - - chdir(StartDir.c_str()); + closedir(D); + if (chdir(StartDir.c_str()) != 0) + return _error->Errno("chdir",_("Unable to change to %s"),StartDir.c_str()); return true; } 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; |