8211326: add OS user related information to hs_err file
authormbaesken
Thu, 15 Nov 2018 17:08:59 +0100
changeset 52585 f7f90fddce02
parent 52584 5ab248e47901
child 52586 74109912c738
8211326: add OS user related information to hs_err file Reviewed-by: dholmes, stuefe
src/hotspot/os/posix/os_posix.cpp
src/hotspot/os/posix/os_posix.hpp
src/hotspot/share/utilities/vmError.cpp
--- a/src/hotspot/os/posix/os_posix.cpp	Thu Nov 15 21:53:30 2018 -0800
+++ b/src/hotspot/os/posix/os_posix.cpp	Thu Nov 15 17:08:59 2018 +0100
@@ -37,6 +37,8 @@
 
 #include <dirent.h>
 #include <dlfcn.h>
+#include <grp.h>
+#include <pwd.h>
 #include <pthread.h>
 #include <signal.h>
 #include <sys/mman.h>
@@ -441,6 +443,38 @@
   st->cr();
 }
 
+void os::Posix::print_umask(outputStream* st, mode_t umsk) {
+  st->print((umsk & S_IRUSR) ? "r" : "-");
+  st->print((umsk & S_IWUSR) ? "w" : "-");
+  st->print((umsk & S_IXUSR) ? "x" : "-");
+  st->print((umsk & S_IRGRP) ? "r" : "-");
+  st->print((umsk & S_IWGRP) ? "w" : "-");
+  st->print((umsk & S_IXGRP) ? "x" : "-");
+  st->print((umsk & S_IROTH) ? "r" : "-");
+  st->print((umsk & S_IWOTH) ? "w" : "-");
+  st->print((umsk & S_IXOTH) ? "x" : "-");
+}
+
+void os::Posix::print_user_info(outputStream* st) {
+  unsigned id = (unsigned) ::getuid();
+  st->print("uid  : %u ", id);
+  id = (unsigned) ::geteuid();
+  st->print("euid : %u ", id);
+  id = (unsigned) ::getgid();
+  st->print("gid  : %u ", id);
+  id = (unsigned) ::getegid();
+  st->print_cr("egid : %u", id);
+  st->cr();
+
+  mode_t umsk = ::umask(0);
+  ::umask(umsk);
+  st->print("umask: %04o (", (unsigned) umsk);
+  print_umask(st, umsk);
+  st->print_cr(")");
+  st->cr();
+}
+
+
 bool os::get_host_name(char* buf, size_t buflen) {
   struct utsname name;
   uname(&name);
--- a/src/hotspot/os/posix/os_posix.hpp	Thu Nov 15 21:53:30 2018 -0800
+++ b/src/hotspot/os/posix/os_posix.hpp	Thu Nov 15 17:08:59 2018 +0100
@@ -117,6 +117,10 @@
   // effective gid, or if given uid is root.
   static bool matches_effective_uid_and_gid_or_root(uid_t uid, gid_t gid);
 
+  static void print_umask(outputStream* st, mode_t umsk);
+
+  static void print_user_info(outputStream* st);
+
 #ifdef SUPPORTS_CLOCK_MONOTONIC
 
   static bool supports_monotonic_clock();
--- a/src/hotspot/share/utilities/vmError.cpp	Thu Nov 15 21:53:30 2018 -0800
+++ b/src/hotspot/share/utilities/vmError.cpp	Thu Nov 15 17:08:59 2018 +0100
@@ -822,6 +822,14 @@
        st->cr();
      }
 
+#ifndef _WIN32
+  STEP("printing user info")
+
+     if (ExtensiveErrorReports && _verbose) {
+       os::Posix::print_user_info(st);
+     }
+#endif
+
   STEP("printing all threads")
 
      // all threads