From e02bd8b99bdcaff9bae401d791236317dd27c6d3 Mon Sep 17 00:00:00 2001 From: Ivor Wanders Date: Fri, 7 Jan 2022 09:25:50 -0500 Subject: [PATCH] Try USER variable to retrieve the username. (#282) Signed-off-by: Ivor Wanders --- src/NetUtils.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/NetUtils.cc b/src/NetUtils.cc index e58365415..f7760ef40 100644 --- a/src/NetUtils.cc +++ b/src/NetUtils.cc @@ -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;