diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2022-11-08 16:03:42 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2022-11-08 16:03:42 +0100 |
commit | 2fde7e0108d70bcba64ebecc5e5c7ee2863e3446 (patch) | |
tree | 3cf91ee071ba96dbca851a695838ea2099ec0c96 /src/libstore/lock.hh | |
parent | 40911d7dec75541a400fe8f556d4c70a7f845fac (diff) |
Split auto UID allocation from cgroups
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).
Diffstat (limited to 'src/libstore/lock.hh')
-rw-r--r-- | src/libstore/lock.hh | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/libstore/lock.hh b/src/libstore/lock.hh index 4b6d34069..62676a523 100644 --- a/src/libstore/lock.hh +++ b/src/libstore/lock.hh @@ -11,18 +11,16 @@ struct UserLock virtual ~UserLock() { } /* Get the first and last UID. */ - virtual std::pair<uid_t, uid_t> getUIDRange() = 0; - - /* Get the first UID. */ - uid_t getUID() + std::pair<uid_t, uid_t> getUIDRange() { - return getUIDRange().first; + auto first = getUID(); + return {first, first + getUIDCount() - 1}; } - uid_t getUIDCount() - { - return getUIDRange().second - getUIDRange().first + 1; - } + /* Get the first UID. */ + virtual uid_t getUID() = 0; + + virtual uid_t getUIDCount() = 0; virtual gid_t getGID() = 0; @@ -31,12 +29,14 @@ struct UserLock /* 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. Note that this may return nullptr if no user - is available. */ -std::unique_ptr<UserLock> acquireUserLock(); +/* 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(); |