Repository: mesos Updated Branches: refs/heads/master 46f1aebde -> 81d830f50
Fix stout/os to properly check errno from getpwnam_r. Support some Linux systems (e.g., RHEL7) which return non-zero and set errno to indicate a user or group was not found. Review: https://reviews.apache.org/r/24249 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/81d830f5 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/81d830f5 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/81d830f5 Branch: refs/heads/master Commit: 81d830f502f99290e4c9fd00f231f0b9fff6b591 Parents: 46f1aeb Author: Ian Downes <[email protected]> Authored: Mon Aug 4 11:36:52 2014 -0700 Committer: Ian Downes <[email protected]> Committed: Mon Aug 4 11:55:21 2014 -0700 ---------------------------------------------------------------------- .../3rdparty/stout/include/stout/os.hpp | 30 +++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/81d830f5/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp index 0117fa5..4d67186 100644 --- a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp +++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp @@ -651,8 +651,8 @@ inline Result<uid_t> getuid(const Option<std::string>& user = None()) char* buffer = new char[size]; if (getpwnam_r(user.get().c_str(), &passwd, buffer, size, &result) == 0) { - // getpwnam_r will return 0 but set result == NULL if the user - // is not found. + // The usual interpretation of POSIX is that getpwnam_r will + // return 0 but set result == NULL if the user is not found. if (result == NULL) { delete[] buffer; return None(); @@ -662,6 +662,17 @@ inline Result<uid_t> getuid(const Option<std::string>& user = None()) delete[] buffer; return uid; } else { + // RHEL7 (and possibly other systems) will return non-zero and + // set one of the following errors for "The given name or uid + // was not found." See 'man getpwnam_r'. We only check for the + // errors explicitly listed, and do not consider the ellipsis. + if (errno == ENOENT || + errno == ESRCH || + errno == EBADF || + errno == EPERM) { + return None(); + } + if (errno != ERANGE) { delete[] buffer; return ErrnoError("Failed to get username information"); @@ -695,8 +706,8 @@ inline Result<gid_t> getgid(const Option<std::string>& user = None()) char* buffer = new char[size]; if (getpwnam_r(user.get().c_str(), &passwd, buffer, size, &result) == 0) { - // getpwnam_r will return 0 but set result == NULL if the user - // is not found. + // The usual interpretation of POSIX is that getpwnam_r will + // return 0 but set result == NULL if the group is not found. if (result == NULL) { delete[] buffer; return None(); @@ -706,6 +717,17 @@ inline Result<gid_t> getgid(const Option<std::string>& user = None()) delete[] buffer; return gid; } else { + // RHEL7 (and possibly other systems) will return non-zero and + // set one of the following errors for "The given name or uid + // was not found." See 'man getpwnam_r'. We only check for the + // errors explicitly listed, and do not consider the ellipsis. + if (errno == ENOENT || + errno == ESRCH || + errno == EBADF || + errno == EPERM) { + return None(); + } + if (errno != ERANGE) { delete[] buffer; return ErrnoError("Failed to get username information");
