Salome HOME
USER or LOGNAME is not defined in a Docker container: on Linux get username with...
[modules/kernel.git] / src / Launcher / Launcher_Job.cxx
index a6d6153ab03f8d28f1b19ef4fcaba8547eb8bc17..b724958185a52363ba6549f74f733231b1e643f5 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2009-2020  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2009-2022  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -37,6 +37,7 @@
 #include <process.h>
 #else
   static const char SEPARATOR = '/';
+#include <pwd.h>
 #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