mirror of
https://github.com/NixOS/nix
synced 2025-07-08 06:53:54 +02:00
Wait for build users when none are available
(cherry picked from commit 880a62b08443a6baa55dab027b69bb8b1551a588)
This commit is contained in:
parent
63ba2fde50
commit
a1469cc8f4
1 changed files with 16 additions and 9 deletions
|
@ -508,6 +508,9 @@ private:
|
||||||
Path fnUserLock;
|
Path fnUserLock;
|
||||||
AutoCloseFD fdUserLock;
|
AutoCloseFD fdUserLock;
|
||||||
|
|
||||||
|
bool findFreeUser();
|
||||||
|
|
||||||
|
|
||||||
string user;
|
string user;
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
gid_t gid;
|
gid_t gid;
|
||||||
|
@ -528,13 +531,22 @@ public:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Sync<PathSet> UserLock::lockedPaths_;
|
Sync<PathSet> UserLock::lockedPaths_;
|
||||||
|
|
||||||
|
|
||||||
UserLock::UserLock()
|
UserLock::UserLock()
|
||||||
{
|
{
|
||||||
assert(settings.buildUsersGroup != "");
|
assert(settings.buildUsersGroup != "");
|
||||||
|
createDirs(settings.nixStateDir + "/userpool");
|
||||||
|
|
||||||
|
if (findFreeUser()) return;
|
||||||
|
|
||||||
|
printError("waiting for build users");
|
||||||
|
|
||||||
|
do std::this_thread::sleep_for(std::chrono::seconds(2)); while (! findFreeUser());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UserLock::findFreeUser() {
|
||||||
|
|
||||||
/* Get the members of the build-users-group. */
|
/* Get the members of the build-users-group. */
|
||||||
struct group * gr = getgrnam(settings.buildUsersGroup.get().c_str());
|
struct group * gr = getgrnam(settings.buildUsersGroup.get().c_str());
|
||||||
|
@ -564,7 +576,6 @@ UserLock::UserLock()
|
||||||
throw Error(format("the user '%1%' in the group '%2%' does not exist")
|
throw Error(format("the user '%1%' in the group '%2%' does not exist")
|
||||||
% i % settings.buildUsersGroup);
|
% i % settings.buildUsersGroup);
|
||||||
|
|
||||||
createDirs(settings.nixStateDir + "/userpool");
|
|
||||||
|
|
||||||
fnUserLock = (format("%1%/userpool/%2%") % settings.nixStateDir % pw->pw_uid).str();
|
fnUserLock = (format("%1%/userpool/%2%") % settings.nixStateDir % pw->pw_uid).str();
|
||||||
|
|
||||||
|
@ -605,20 +616,17 @@ UserLock::UserLock()
|
||||||
supplementaryGIDs.resize(ngroups);
|
supplementaryGIDs.resize(ngroups);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
lockedPaths_.lock()->erase(fnUserLock);
|
lockedPaths_.lock()->erase(fnUserLock);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
throw Error(format("all build users are currently in use; "
|
|
||||||
"consider creating additional users and adding them to the '%1%' group")
|
|
||||||
% settings.buildUsersGroup);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
UserLock::~UserLock()
|
UserLock::~UserLock()
|
||||||
{
|
{
|
||||||
auto lockedPaths(lockedPaths_.lock());
|
auto lockedPaths(lockedPaths_.lock());
|
||||||
|
@ -626,7 +634,6 @@ UserLock::~UserLock()
|
||||||
lockedPaths->erase(fnUserLock);
|
lockedPaths->erase(fnUserLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void UserLock::kill()
|
void UserLock::kill()
|
||||||
{
|
{
|
||||||
killUser(uid);
|
killUser(uid);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue