Skip to content

Commit

Permalink
Try USER variable to retrieve the username. (#282)
Browse files Browse the repository at this point in the history
Signed-off-by: Ivor Wanders <[email protected]>
  • Loading branch information
iwanders authored Jan 7, 2022
1 parent f3c8f8b commit e02bd8b
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 userVariable = std::getenv("USER");
if (userVariable)
{
return userVariable;
}

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

0 comments on commit e02bd8b

Please sign in to comment.