// 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;
}
delete [] Buffer;
if (chdir(Cwd.c_str()) != 0)
- chdir("/");
-
+ return _error->Errno("chdir",_("Unable to change to %s"),Cwd.c_str());
return !_error->PendingError();
}
/*}}}*/
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 /*{{{*/
// ---------------------------------------------------------------------
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;
}
}
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);
}
<< ":" << 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;
<< ":" << 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++;
<< ":" << 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;
<< ":" << 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;
}
}
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
<< (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();
- 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
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;
}
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, /*{{{*/
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;
}
}
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;
}
}
}
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;