Check if getpwuid_r failed to find a password entry
Check if getpwuid_r failed to find a password entry
([arc::pullid] 4d84fecf-25d8a32a-8cd9018d-2e828d76)
@@ -38,13 +38,12 @@ TString GetUsername() {
passwd pwd;
passwd* tmpPwd;
int err = getpwuid_r(geteuid(), &pwd, nameBuf.Data(), nameBuf.Size(), &tmpPwd);
- if (err) {
- if (err == ERANGE)
+ if (err == 0 && tmpPwd) {
+ return TString(pwd.pw_name);
+ } else if (err == ERANGE) {
nameBuf = TTempBuf(nameBuf.Size() * 2);
- else
- ythrow TSystemError(err) << " getpwuid_r failed";
} else {
- return TString(pwd.pw_name);
+ ythrow TSystemError(err) << " getpwuid_r failed";
}
#endif
}
