Merge pull request #9229 from tfc/small-improvements
Remove warnings, small improvements
(cherry picked from commit 5ac87a75dd65c19c50976559a6f7810c315cd9d5)
Change-Id: I88349b6e954398dde83c845f42d41a9dd89ba9e0
This commit is contained in:
parent
ea10088703
commit
8abb20390e
|
@ -174,15 +174,19 @@ void builtinBuildenv(const BasicDerivation & drv)
|
||||||
/* Convert the stuff we get from the environment back into a
|
/* Convert the stuff we get from the environment back into a
|
||||||
* coherent data type. */
|
* coherent data type. */
|
||||||
Packages pkgs;
|
Packages pkgs;
|
||||||
|
{
|
||||||
auto derivations = tokenizeString<Strings>(getAttr("derivations"));
|
auto derivations = tokenizeString<Strings>(getAttr("derivations"));
|
||||||
while (!derivations.empty()) {
|
|
||||||
|
auto itemIt = derivations.begin();
|
||||||
|
while (itemIt != derivations.end()) {
|
||||||
/* !!! We're trusting the caller to structure derivations env var correctly */
|
/* !!! We're trusting the caller to structure derivations env var correctly */
|
||||||
auto active = derivations.front(); derivations.pop_front();
|
const bool active = "false" != *itemIt++;
|
||||||
auto priority = stoi(derivations.front()); derivations.pop_front();
|
const int priority = stoi(*itemIt++);
|
||||||
auto outputs = stoi(derivations.front()); derivations.pop_front();
|
const size_t outputs = stoul(*itemIt++);
|
||||||
for (auto n = 0; n < outputs; n++) {
|
|
||||||
auto path = derivations.front(); derivations.pop_front();
|
for (size_t n {0}; n < outputs; n++) {
|
||||||
pkgs.emplace_back(path, active != "false", priority);
|
pkgs.emplace_back(std::move(*itemIt++), active, priority);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,12 +29,13 @@ std::string ContentAddressMethod::renderPrefix() const
|
||||||
|
|
||||||
ContentAddressMethod ContentAddressMethod::parsePrefix(std::string_view & m)
|
ContentAddressMethod ContentAddressMethod::parsePrefix(std::string_view & m)
|
||||||
{
|
{
|
||||||
ContentAddressMethod method = FileIngestionMethod::Flat;
|
if (splitPrefix(m, "r:")) {
|
||||||
if (splitPrefix(m, "r:"))
|
return FileIngestionMethod::Recursive;
|
||||||
method = FileIngestionMethod::Recursive;
|
}
|
||||||
else if (splitPrefix(m, "text:"))
|
else if (splitPrefix(m, "text:")) {
|
||||||
method = TextIngestionMethod {};
|
return TextIngestionMethod {};
|
||||||
return method;
|
}
|
||||||
|
return FileIngestionMethod::Flat;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ContentAddressMethod::render(HashType ht) const
|
std::string ContentAddressMethod::render(HashType ht) const
|
||||||
|
|
|
@ -7,6 +7,31 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
#if __linux__
|
||||||
|
|
||||||
|
static std::vector<gid_t> get_group_list(const char *username, gid_t group_id)
|
||||||
|
{
|
||||||
|
std::vector<gid_t> gids;
|
||||||
|
gids.resize(32); // Initial guess
|
||||||
|
|
||||||
|
auto getgroupl_failed {[&] {
|
||||||
|
int ngroups = gids.size();
|
||||||
|
int err = getgrouplist(username, group_id, gids.data(), &ngroups);
|
||||||
|
gids.resize(ngroups);
|
||||||
|
return err == -1;
|
||||||
|
}};
|
||||||
|
|
||||||
|
// The first error means that the vector was not big enough.
|
||||||
|
// If it happens again, there is some different problem.
|
||||||
|
if (getgroupl_failed() && getgroupl_failed()) {
|
||||||
|
throw SysError("failed to get list of supplementary groups for '%s'", username);
|
||||||
|
}
|
||||||
|
|
||||||
|
return gids;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
struct SimpleUserLock : UserLock
|
struct SimpleUserLock : UserLock
|
||||||
{
|
{
|
||||||
AutoCloseFD fdUserLock;
|
AutoCloseFD fdUserLock;
|
||||||
|
@ -67,37 +92,14 @@ struct SimpleUserLock : UserLock
|
||||||
throw Error("the Nix user should not be a member of '%s'", settings.buildUsersGroup);
|
throw Error("the Nix user should not be a member of '%s'", settings.buildUsersGroup);
|
||||||
|
|
||||||
#if __linux__
|
#if __linux__
|
||||||
/* Get the list of supplementary groups of this build
|
/* Get the list of supplementary groups of this user. This is
|
||||||
user. This is usually either empty or contains a
|
* usually either empty or contains a group such as "kvm". */
|
||||||
group such as "kvm". */
|
|
||||||
int ngroups = 32; // arbitrary initial guess
|
|
||||||
std::vector<gid_t> gids;
|
|
||||||
gids.resize(ngroups);
|
|
||||||
|
|
||||||
int err = getgrouplist(
|
|
||||||
pw->pw_name, pw->pw_gid,
|
|
||||||
gids.data(),
|
|
||||||
&ngroups);
|
|
||||||
|
|
||||||
/* Our initial size of 32 wasn't sufficient, the
|
|
||||||
correct size has been stored in ngroups, so we try
|
|
||||||
again. */
|
|
||||||
if (err == -1) {
|
|
||||||
gids.resize(ngroups);
|
|
||||||
err = getgrouplist(
|
|
||||||
pw->pw_name, pw->pw_gid,
|
|
||||||
gids.data(),
|
|
||||||
&ngroups);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If it failed once more, then something must be broken.
|
|
||||||
if (err == -1)
|
|
||||||
throw Error("failed to get list of supplementary groups for '%s'", pw->pw_name);
|
|
||||||
|
|
||||||
// Finally, trim back the GID list to its real size.
|
// Finally, trim back the GID list to its real size.
|
||||||
for (auto i = 0; i < ngroups; i++)
|
for (auto gid : get_group_list(pw->pw_name, pw->pw_gid)) {
|
||||||
if (gids[i] != lock->gid)
|
if (gid != lock->gid)
|
||||||
lock->supplementaryGIDs.push_back(gids[i]);
|
lock->supplementaryGIDs.push_back(gid);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return lock;
|
return lock;
|
||||||
|
|
Loading…
Reference in a new issue