diff options
Diffstat (limited to 'paludis/util/process.cc')
-rw-r--r-- | paludis/util/process.cc | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/paludis/util/process.cc b/paludis/util/process.cc index b4b553db1..380d671d6 100644 --- a/paludis/util/process.cc +++ b/paludis/util/process.cc @@ -17,6 +17,7 @@ * Place, Suite 330, Boston, MA 02111-1307 USA */ +#include <paludis/util/persona.hh> #include <paludis/util/process.hh> #include <paludis/util/pimp-impl.hh> #include <paludis/util/pipe.hh> @@ -806,17 +807,14 @@ Process::run() if (0 != ::setgid(_imp->setgid)) throw ProcessError("setgid() failed"); - int buflen(::sysconf(_SC_GETPW_R_SIZE_MAX)); - if (-1 == buflen) - buflen = 1 << 16; + struct passwd pwd; + struct passwd *result; + std::vector<char> buffer; - std::unique_ptr<char []> buf(new char[buflen]); - struct passwd pw; - struct passwd * pw_result(nullptr); - if (0 != getpwuid_r(_imp->setuid, &pw, buf.get(), buflen, &pw_result) || nullptr == pw_result) + if (0 != getpwuid_r_s(_imp->setuid, buffer, pwd, result) || result == nullptr) throw ProcessError("getpwuid_r() failed"); - if (0 != ::initgroups(pw_result->pw_name, getgid())) + if (0 != ::initgroups(pwd.pw_name, getgid())) throw ProcessError("initgroups() failed"); if (0 != ::setuid(_imp->setuid)) |