diff src/os/linux/vm/perfMemory_linux.cpp @ 23455:9f8038f83a6e

8130910: hsperfdata file is created in wrong directory and not cleaned up if /tmp/hsperfdata_<username> has wrong permissions Summary: Add check for fchir() failure and disable shared PerfMemory in that case. Reviewed-by: dcubed, simonis, gthornbr
author clanger
date Tue, 17 Nov 2015 09:39:45 -0800
parents decf7079a7b9
children b5f3a471e646
line wrap: on
line diff
--- a/src/os/linux/vm/perfMemory_linux.cpp	Thu Oct 29 14:08:19 2015 +0300
+++ b/src/os/linux/vm/perfMemory_linux.cpp	Tue Nov 17 09:39:45 2015 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -374,10 +374,23 @@
     *saved_cwd_fd = result;
   }
 
-  // Set the current directory to dirname by using the fd of the directory.
+  // Set the current directory to dirname by using the fd of the directory and
+  // handle errors, otherwise shared memory files will be created in cwd.
   result = fchdir(fd);
-
-  return dirp;
+  if (result == OS_ERR) {
+    if (PrintMiscellaneous && Verbose) {
+      warning("could not change to directory %s", dirname);
+    }
+    if (*saved_cwd_fd != -1) {
+      ::close(*saved_cwd_fd);
+      *saved_cwd_fd = -1;
+    }
+    // Close the directory.
+    os::closedir(dirp);
+    return NULL;
+  } else {
+    return dirp;
+  }
 }
 
 // Close the directory and restore the current working directory.