From a90309e7a72b9642316eda15e8f422772ad2971f Mon Sep 17 00:00:00 2001 From: Gilles DAVID Date: Thu, 30 Mar 2023 19:13:55 +0200 Subject: [PATCH] USER or LOGNAME is not defined in a Docker container: on Linux get username with getpwuid(getuid()) --- src/Launcher/Launcher_Job.cxx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Launcher/Launcher_Job.cxx b/src/Launcher/Launcher_Job.cxx index e878a7404..b72495818 100644 --- a/src/Launcher/Launcher_Job.cxx +++ b/src/Launcher/Launcher_Job.cxx @@ -37,6 +37,7 @@ #include #else static const char SEPARATOR = '/'; +#include #endif Launcher::Job::Job() @@ -191,7 +192,12 @@ Launcher::Job::setResourceDefinition(const ParserResourcesType & resource_defini if (resource_definition.UserName == "") { #ifndef WIN32 - user_name = getenv("USER"); + struct passwd *pwd = getpwuid(getuid()); + if (pwd) { + user_name = std::string(pwd->pw_name); + } + if (user_name == "") + user_name = getenv("USER"); #else user_name = getenv("USERNAME"); #endif -- 2.39.2