Skip to content

Commit

Permalink
Try USER variable to retrieve the username.
Browse files Browse the repository at this point in the history
Signed-off-by: Ivor Wanders <[email protected]>
  • Loading branch information
iwanders committed Dec 20, 2021
1 parent f3c8f8b commit 54d9b66
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/NetUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,15 @@ inline namespace IGNITION_TRANSPORT_VERSION_NAMESPACE
GetUserName(buffer, &usernameLen);
return buffer;
#else
// First, try to get the username through the standard environment variable
// for it.
const auto user_variable = std::getenv("USER");
if (user_variable)
{
return user_variable;
}

// No USER variable, request it from the system.
struct passwd pd;
struct passwd *pdResult;
Uuid uuid;
Expand Down

0 comments on commit 54d9b66

Please sign in to comment.