diff options
Diffstat (limited to 'src/libstore/lock.cc')
-rw-r--r-- | src/libstore/lock.cc | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/libstore/lock.cc b/src/libstore/lock.cc index 02ccb1186..cc3977496 100644 --- a/src/libstore/lock.cc +++ b/src/libstore/lock.cc @@ -80,13 +80,30 @@ struct SimpleUserLock : UserLock /* Get the list of supplementary groups of this build user. This is usually either empty or contains a group such as "kvm". */ - lock->supplementaryGIDs.resize(10); - int ngroups = lock->supplementaryGIDs.size(); - int err = getgrouplist(pw->pw_name, pw->pw_gid, - lock->supplementaryGIDs.data(), &ngroups); + int ngroups = 32; // arbitrary initial guess + lock->supplementaryGIDs.resize(ngroups); + + int err = getgrouplist( + pw->pw_name, pw->pw_gid, + lock->supplementaryGIDs.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) { + lock->supplementaryGIDs.resize(ngroups); + err = getgrouplist( + pw->pw_name, pw->pw_gid, + lock->supplementaryGIDs.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. lock->supplementaryGIDs.resize(ngroups); #endif |