forked from lix-project/lix
2fde7e0108
Cgroups are now only used for derivations that require the uid-range range feature. This allows auto UID allocation even on systems that don't have cgroups (like macOS). Also, make things work on modern systems that use cgroups v2 (where there is a single hierarchy and no "systemd" controller).
44 lines
877 B
C++
44 lines
877 B
C++
#pragma once
|
|
|
|
#include "types.hh"
|
|
|
|
#include <optional>
|
|
|
|
namespace nix {
|
|
|
|
struct UserLock
|
|
{
|
|
virtual ~UserLock() { }
|
|
|
|
/* Get the first and last UID. */
|
|
std::pair<uid_t, uid_t> getUIDRange()
|
|
{
|
|
auto first = getUID();
|
|
return {first, first + getUIDCount() - 1};
|
|
}
|
|
|
|
/* Get the first UID. */
|
|
virtual uid_t getUID() = 0;
|
|
|
|
virtual uid_t getUIDCount() = 0;
|
|
|
|
virtual gid_t getGID() = 0;
|
|
|
|
virtual std::vector<gid_t> getSupplementaryGIDs() = 0;
|
|
|
|
/* Kill any processes currently executing as this user. */
|
|
virtual void kill() = 0;
|
|
|
|
#if __linux__
|
|
virtual std::optional<Path> getCgroup() { return {}; };
|
|
#endif
|
|
};
|
|
|
|
/* Acquire a user lock for a UID range of size `nrIds`. Note that this
|
|
may return nullptr if no user is available. */
|
|
std::unique_ptr<UserLock> acquireUserLock(uid_t nrIds);
|
|
|
|
bool useBuildUsers();
|
|
|
|
}
|