aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/lock.hh
blob: 4b6d34069ed15bcc8caaf1a5900fc56de43149b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#pragma once

#include "types.hh"

#include <optional>

namespace nix {

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()
    {
        return getUIDRange().first;
    }

    uid_t getUIDCount()
    {
        return getUIDRange().second - getUIDRange().first + 1;
    }

    virtual gid_t getGID() = 0;

    virtual std::vector<gid_t> getSupplementaryGIDs() = 0;

    /* Kill any processes currently executing as this user. */
    virtual void kill() = 0;

    virtual std::optional<Path> getCgroup() { return {}; };
};

/* Acquire a user lock. Note that this may return nullptr if no user
   is available. */
std::unique_ptr<UserLock> acquireUserLock();

bool useBuildUsers();

}