#include <string>
#include <utility>
#include <vector>
+#include <sstream>
#include <apti18n.h>
/*}}}*/
using namespace std;
+APT_PURE static string
+AptHistoryUser()
+{
+ stringstream out;
+ const char* env[]{"SUDO_USER", "PKEXEC_UID", nullptr};
+ for (int i=0; env[i] != nullptr; i++)
+ {
+ if (getenv(env[i]) != nullptr)
+ {
+ out << env[i] << "=" << getenv(env[i]) << " ";
+ }
+ }
+ return out.str();
+}
+
APT_PURE static unsigned int
EnvironmentSize()
{
bool stdin_is_dev_null;
// the buffer we use for the dpkg status-fd reading
char dpkgbuf[1024];
- int dpkgbuf_pos;
+ size_t dpkgbuf_pos;
FILE *term_out;
FILE *history_out;
string dpkg_error;
const char *target;
public:
- MatchProcessingOp(const char *the_target)
+ explicit MatchProcessingOp(const char *the_target)
: target(the_target)
{
}
}
/*}}}*/
// DPkgPM::DoDpkgStatusFd /*{{{*/
-// ---------------------------------------------------------------------
-/*
- */
void pkgDPkgPM::DoDpkgStatusFd(int statusfd)
{
- char *p, *q;
- int len;
-
- len=read(statusfd, &d->dpkgbuf[d->dpkgbuf_pos], sizeof(d->dpkgbuf)-d->dpkgbuf_pos);
- d->dpkgbuf_pos += len;
+ ssize_t const len = read(statusfd, &d->dpkgbuf[d->dpkgbuf_pos],
+ (sizeof(d->dpkgbuf)/sizeof(d->dpkgbuf[0])) - d->dpkgbuf_pos);
if(len <= 0)
return;
+ d->dpkgbuf_pos += (len / sizeof(d->dpkgbuf[0]));
- // process line by line if we have a buffer
- p = q = d->dpkgbuf;
- while((q=(char*)memchr(p, '\n', d->dpkgbuf+d->dpkgbuf_pos-p)) != NULL)
+ // process line by line from the buffer
+ char *p = d->dpkgbuf, *q = nullptr;
+ while((q=(char*)memchr(p, '\n', (d->dpkgbuf + d->dpkgbuf_pos) - p)) != nullptr)
{
- *q = 0;
+ *q = '\0';
ProcessDpkgStatusLine(p);
- p=q+1; // continue with next line
+ p = q + 1; // continue with next line
}
- // now move the unprocessed bits (after the final \n that is now a 0x0)
- // to the start and update d->dpkgbuf_pos
- p = (char*)memrchr(d->dpkgbuf, 0, d->dpkgbuf_pos);
- if(p == NULL)
+ // check if we stripped the buffer clean
+ if (p > (d->dpkgbuf + d->dpkgbuf_pos))
+ {
+ d->dpkgbuf_pos = 0;
return;
+ }
- // we are interessted in the first char *after* 0x0
- p++;
-
- // move the unprocessed tail to the start and update pos
- memmove(d->dpkgbuf, p, p-d->dpkgbuf);
- d->dpkgbuf_pos = d->dpkgbuf+d->dpkgbuf_pos-p;
+ // otherwise move the unprocessed tail to the start and update pos
+ memmove(d->dpkgbuf, p, (p - d->dpkgbuf));
+ d->dpkgbuf_pos = (d->dpkgbuf + d->dpkgbuf_pos) - p;
}
/*}}}*/
// DPkgPM::WriteHistoryTag /*{{{*/
}
if (_config->Exists("Commandline::AsString") == true)
WriteHistoryTag("Commandline", _config->Find("Commandline::AsString"));
+ if (AptHistoryUser() != "")
+ WriteHistoryTag("Requested-By", AptHistoryUser());
WriteHistoryTag("Install", install);
WriteHistoryTag("Reinstall", reinstall);
WriteHistoryTag("Upgrade", upgrade);
std::vector<const char *> Args(sArgs.size(), NULL);
std::transform(sArgs.begin(), sArgs.end(), Args.begin(),
[](std::string const &s) { return s.c_str(); });
- unsigned long long const StartSize = std::accumulate(sArgs.begin(), sArgs.end(), 0,
+ unsigned long long const StartSize = std::accumulate(sArgs.begin(), sArgs.end(), 0llu,
[](unsigned long long const i, std::string const &s) { return i + s.length(); });
size_t const BaseArgs = Args.size();
{
std::string const oldpkgcache = _config->FindFile("Dir::cache::pkgcache");
if (oldpkgcache.empty() == false && RealFileExists(oldpkgcache) == true &&
- unlink(oldpkgcache.c_str()) == 0)
+ RemoveFile("pkgDPkgPM::Go", oldpkgcache))
{
std::string const srcpkgcache = _config->FindFile("Dir::cache::srcpkgcache");
if (srcpkgcache.empty() == false && RealFileExists(srcpkgcache) == true)
if(pos != string::npos)
pkgname = pkgname.substr(0, pos);
- // find the package versin and source package name
+ // find the package version and source package name
pkgCache::PkgIterator Pkg = Cache.FindPkg(pkgname);
if (Pkg.end() == true)
return;
- pkgCache::VerIterator Ver = Cache.GetCandidateVer(Pkg);
+ pkgCache::VerIterator Ver = Cache.GetCandidateVersion(Pkg);
if (Ver.end() == true)
return;
pkgver = Ver.VerStr() == NULL ? "unknown" : Ver.VerStr();