jdk/src/java.base/linux/native/libjava/ProcessHandleImpl_linux.c
changeset 32517 47fa336854c3
parent 32209 24bb680a1609
child 40179 b5d59a6f093a
--- a/jdk/src/java.base/linux/native/libjava/ProcessHandleImpl_linux.c	Fri Sep 11 13:44:30 2015 +0300
+++ b/jdk/src/java.base/linux/native/libjava/ProcessHandleImpl_linux.c	Fri Sep 11 09:25:15 2015 -0400
@@ -141,17 +141,21 @@
     struct stat stat_buf;
 
     /*
+     * Stat /proc/<pid> to get the user id
+     */
+    snprintf(fn, sizeof fn, "/proc/%d", pid);
+    if (stat(fn, &stat_buf) == 0) {
+        unix_getUserInfo(env, jinfo, stat_buf.st_uid);
+    }
+
+    /*
      * Try to open /proc/<pid>/cmdline
      */
-    snprintf(fn, sizeof fn, "/proc/%d/cmdline", pid);
+    strncat(fn, "/cmdline", sizeof fn - strnlen(fn, sizeof fn) - 1);
     if ((fd = open(fn, O_RDONLY)) < 0) {
         return;
     }
 
-    if (fstat(fd, &stat_buf) == 0) {
-        unix_getUserInfo(env, jinfo, stat_buf.st_uid);
-    }
-
     do {                // Block to break out of on errors
         int i, truncated = 0;
         int count;