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 17, 2021
1 parent f3c8f8b commit 8d09ed2
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/NetUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,14 @@ 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 8d09ed2

Please sign in to comment.