< prev index next >

src/os/linux/vm/perfMemory_linux.cpp

Print this page


   1 /*
   2  * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 357 //
 358 static DIR *open_directory_secure_cwd(const char* dirname, int *saved_cwd_fd) {
 359 
 360   // Open the directory.
 361   DIR* dirp = open_directory_secure(dirname);
 362   if (dirp == NULL) {
 363     // Directory doesn't exist or is insecure, so there is nothing to cleanup.
 364     return dirp;
 365   }
 366   int fd = dirfd(dirp);
 367 
 368   // Open a fd to the cwd and save it off.
 369   int result;
 370   RESTARTABLE(::open(".", O_RDONLY), result);
 371   if (result == OS_ERR) {
 372     *saved_cwd_fd = -1;
 373   } else {
 374     *saved_cwd_fd = result;
 375   }
 376 
 377   // Set the current directory to dirname by using the fd of the directory.

 378   result = fchdir(fd);
 379 











 380   return dirp;

 381 }
 382 
 383 // Close the directory and restore the current working directory.
 384 //
 385 static void close_directory_secure_cwd(DIR* dirp, int saved_cwd_fd) {
 386 
 387   int result;
 388   // If we have a saved cwd change back to it and close the fd.
 389   if (saved_cwd_fd != -1) {
 390     result = fchdir(saved_cwd_fd);
 391     ::close(saved_cwd_fd);
 392   }
 393 
 394   // Close the directory.
 395   os::closedir(dirp);
 396 }
 397 
 398 // Check if the given file descriptor is considered a secure.
 399 //
 400 static bool is_file_secure(int fd, const char *filename) {


   1 /*
   2  * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 357 //
 358 static DIR *open_directory_secure_cwd(const char* dirname, int *saved_cwd_fd) {
 359 
 360   // Open the directory.
 361   DIR* dirp = open_directory_secure(dirname);
 362   if (dirp == NULL) {
 363     // Directory doesn't exist or is insecure, so there is nothing to cleanup.
 364     return dirp;
 365   }
 366   int fd = dirfd(dirp);
 367 
 368   // Open a fd to the cwd and save it off.
 369   int result;
 370   RESTARTABLE(::open(".", O_RDONLY), result);
 371   if (result == OS_ERR) {
 372     *saved_cwd_fd = -1;
 373   } else {
 374     *saved_cwd_fd = result;
 375   }
 376 
 377   // Set the current directory to dirname by using the fd of the directory and
 378   // handle errors, otherwise shared memory files will be created in cwd.
 379   result = fchdir(fd);
 380   if (result == OS_ERR) {
 381     if (PrintMiscellaneous && Verbose) {
 382       warning("could not change to directory %s", dirname);
 383     }
 384     if (*saved_cwd_fd != -1) {
 385       ::close(*saved_cwd_fd);
 386       *saved_cwd_fd = -1;
 387     }
 388     // Close the directory.
 389     os::closedir(dirp);
 390     return NULL;
 391   } else {
 392     return dirp;
 393   }
 394 }
 395 
 396 // Close the directory and restore the current working directory.
 397 //
 398 static void close_directory_secure_cwd(DIR* dirp, int saved_cwd_fd) {
 399 
 400   int result;
 401   // If we have a saved cwd change back to it and close the fd.
 402   if (saved_cwd_fd != -1) {
 403     result = fchdir(saved_cwd_fd);
 404     ::close(saved_cwd_fd);
 405   }
 406 
 407   // Close the directory.
 408   os::closedir(dirp);
 409 }
 410 
 411 // Check if the given file descriptor is considered a secure.
 412 //
 413 static bool is_file_secure(int fd, const char *filename) {


< prev index next >