mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8202353: os::readdir should use readdir instead of readdir_r
8202835: jfr/event/os/TestSystemProcess.java fails on missing events Os::readdir uses POSIX readdir, drop buffer arg, fix JFR uses. Reviewed-by: coleenp, tschatzl, bsrbnd
This commit is contained in:
parent
f4723253b6
commit
9a9c824ece
22 changed files with 54 additions and 238 deletions
|
@ -3733,8 +3733,7 @@ bool os::dir_is_empty(const char* path) {
|
||||||
|
|
||||||
/* Scan the directory */
|
/* Scan the directory */
|
||||||
bool result = true;
|
bool result = true;
|
||||||
char buf[sizeof(struct dirent) + MAX_PATH];
|
while (result && (ptr = readdir(dir)) != NULL) {
|
||||||
while (result && (ptr = ::readdir(dir)) != NULL) {
|
|
||||||
if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
|
if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,17 +74,6 @@ inline void os::dll_unload(void *lib) {
|
||||||
|
|
||||||
inline const int os::default_file_open_flags() { return 0;}
|
inline const int os::default_file_open_flags() { return 0;}
|
||||||
|
|
||||||
inline DIR* os::opendir(const char* dirname) {
|
|
||||||
assert(dirname != NULL, "just checking");
|
|
||||||
return ::opendir(dirname);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int os::readdir_buf_size(const char *path) {
|
|
||||||
// According to aix sys/limits, NAME_MAX must be retrieved at runtime.
|
|
||||||
const long my_NAME_MAX = pathconf(path, _PC_NAME_MAX);
|
|
||||||
return my_NAME_MAX + sizeof(dirent) + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline jlong os::lseek(int fd, jlong offset, int whence) {
|
inline jlong os::lseek(int fd, jlong offset, int whence) {
|
||||||
return (jlong) ::lseek64(fd, offset, whence);
|
return (jlong) ::lseek64(fd, offset, whence);
|
||||||
}
|
}
|
||||||
|
@ -97,23 +86,6 @@ inline int os::ftruncate(int fd, jlong length) {
|
||||||
return ::ftruncate64(fd, length);
|
return ::ftruncate64(fd, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf) {
|
|
||||||
dirent* p = NULL;
|
|
||||||
assert(dirp != NULL, "just checking");
|
|
||||||
|
|
||||||
// AIX: slightly different from POSIX.
|
|
||||||
// On AIX, readdir_r returns 0 or != 0 and error details in errno.
|
|
||||||
if (::readdir_r(dirp, dbuf, &p) != 0) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int os::closedir(DIR *dirp) {
|
|
||||||
assert(dirp != NULL, "argument is NULL");
|
|
||||||
return ::closedir(dirp);
|
|
||||||
}
|
|
||||||
|
|
||||||
// macros for restartable system calls
|
// macros for restartable system calls
|
||||||
|
|
||||||
#define RESTARTABLE(_cmd, _result) do { \
|
#define RESTARTABLE(_cmd, _result) do { \
|
||||||
|
|
|
@ -893,21 +893,14 @@ int SystemProcessInterface::SystemProcesses::ProcessIterator::current(SystemProc
|
||||||
}
|
}
|
||||||
|
|
||||||
int SystemProcessInterface::SystemProcesses::ProcessIterator::next_process() {
|
int SystemProcessInterface::SystemProcesses::ProcessIterator::next_process() {
|
||||||
struct dirent* entry;
|
|
||||||
|
|
||||||
if (!is_valid()) {
|
if (!is_valid()) {
|
||||||
return OS_ERR;
|
return OS_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
entry = os::readdir(_dir, _entry);
|
_entry = os::readdir(_dir);
|
||||||
if (entry == NULL) {
|
|
||||||
// error
|
|
||||||
_valid = false;
|
|
||||||
return OS_ERR;
|
|
||||||
}
|
|
||||||
if (_entry == NULL) {
|
if (_entry == NULL) {
|
||||||
// reached end
|
// Error or reached end. Could use errno to distinguish those cases.
|
||||||
_valid = false;
|
_valid = false;
|
||||||
return OS_ERR;
|
return OS_ERR;
|
||||||
}
|
}
|
||||||
|
@ -929,11 +922,8 @@ bool SystemProcessInterface::SystemProcesses::ProcessIterator::initialize() {
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemProcessInterface::SystemProcesses::ProcessIterator::~ProcessIterator() {
|
SystemProcessInterface::SystemProcesses::ProcessIterator::~ProcessIterator() {
|
||||||
if (_entry != NULL) {
|
|
||||||
FREE_C_HEAP_ARRAY(char, _entry);
|
|
||||||
}
|
|
||||||
if (_dir != NULL) {
|
if (_dir != NULL) {
|
||||||
closedir(_dir);
|
os::closedir(_dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -617,9 +617,8 @@ static char* get_user_name_slow(int vmid, TRAPS) {
|
||||||
// to determine the user name for the process id.
|
// to determine the user name for the process id.
|
||||||
//
|
//
|
||||||
struct dirent* dentry;
|
struct dirent* dentry;
|
||||||
char* tdbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(tmpdirname), mtInternal);
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
while ((dentry = os::readdir(tmpdirp, (struct dirent *)tdbuf)) != NULL) {
|
while ((dentry = os::readdir(tmpdirp)) != NULL) {
|
||||||
|
|
||||||
// check if the directory entry is a hsperfdata file
|
// check if the directory entry is a hsperfdata file
|
||||||
if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) {
|
if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) {
|
||||||
|
@ -653,9 +652,8 @@ static char* get_user_name_slow(int vmid, TRAPS) {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct dirent* udentry;
|
struct dirent* udentry;
|
||||||
char* udbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(usrdir_name), mtInternal);
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
while ((udentry = os::readdir(subdirp, (struct dirent *)udbuf)) != NULL) {
|
while ((udentry = os::readdir(subdirp)) != NULL) {
|
||||||
|
|
||||||
if (filename_to_pid(udentry->d_name) == vmid) {
|
if (filename_to_pid(udentry->d_name) == vmid) {
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
|
@ -699,11 +697,9 @@ static char* get_user_name_slow(int vmid, TRAPS) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
os::closedir(subdirp);
|
os::closedir(subdirp);
|
||||||
FREE_C_HEAP_ARRAY(char, udbuf);
|
|
||||||
FREE_C_HEAP_ARRAY(char, usrdir_name);
|
FREE_C_HEAP_ARRAY(char, usrdir_name);
|
||||||
}
|
}
|
||||||
os::closedir(tmpdirp);
|
os::closedir(tmpdirp);
|
||||||
FREE_C_HEAP_ARRAY(char, tdbuf);
|
|
||||||
|
|
||||||
return(oldest_user);
|
return(oldest_user);
|
||||||
}
|
}
|
||||||
|
@ -779,10 +775,8 @@ static void cleanup_sharedmem_resources(const char* dirname) {
|
||||||
// loop under these conditions is dependent upon the implementation of
|
// loop under these conditions is dependent upon the implementation of
|
||||||
// opendir/readdir.
|
// opendir/readdir.
|
||||||
struct dirent* entry;
|
struct dirent* entry;
|
||||||
char* dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(dirname), mtInternal);
|
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
while ((entry = os::readdir(dirp, (struct dirent *)dbuf)) != NULL) {
|
while ((entry = os::readdir(dirp)) != NULL) {
|
||||||
|
|
||||||
pid_t pid = filename_to_pid(entry->d_name);
|
pid_t pid = filename_to_pid(entry->d_name);
|
||||||
|
|
||||||
|
@ -820,8 +814,6 @@ static void cleanup_sharedmem_resources(const char* dirname) {
|
||||||
|
|
||||||
// Close the directory and reset the current working directory.
|
// Close the directory and reset the current working directory.
|
||||||
close_directory_secure_cwd(dirp, saved_cwd_fd);
|
close_directory_secure_cwd(dirp, saved_cwd_fd);
|
||||||
|
|
||||||
FREE_C_HEAP_ARRAY(char, dbuf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make the user specific temporary directory. Returns true if
|
// Make the user specific temporary directory. Returns true if
|
||||||
|
|
|
@ -3506,8 +3506,7 @@ bool os::dir_is_empty(const char* path) {
|
||||||
|
|
||||||
// Scan the directory
|
// Scan the directory
|
||||||
bool result = true;
|
bool result = true;
|
||||||
char buf[sizeof(struct dirent) + MAX_PATH];
|
while (result && (ptr = readdir(dir)) != NULL) {
|
||||||
while (result && (ptr = ::readdir(dir)) != NULL) {
|
|
||||||
if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
|
if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,17 +77,6 @@ inline void os::dll_unload(void *lib) {
|
||||||
|
|
||||||
inline const int os::default_file_open_flags() { return 0;}
|
inline const int os::default_file_open_flags() { return 0;}
|
||||||
|
|
||||||
inline DIR* os::opendir(const char* dirname)
|
|
||||||
{
|
|
||||||
assert(dirname != NULL, "just checking");
|
|
||||||
return ::opendir(dirname);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int os::readdir_buf_size(const char *path)
|
|
||||||
{
|
|
||||||
return NAME_MAX + sizeof(dirent) + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline jlong os::lseek(int fd, jlong offset, int whence) {
|
inline jlong os::lseek(int fd, jlong offset, int whence) {
|
||||||
return (jlong) ::lseek(fd, offset, whence);
|
return (jlong) ::lseek(fd, offset, whence);
|
||||||
}
|
}
|
||||||
|
@ -100,28 +89,6 @@ inline int os::ftruncate(int fd, jlong length) {
|
||||||
return ::ftruncate(fd, length);
|
return ::ftruncate(fd, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf)
|
|
||||||
{
|
|
||||||
dirent* p;
|
|
||||||
int status;
|
|
||||||
assert(dirp != NULL, "just checking");
|
|
||||||
|
|
||||||
// NOTE: Bsd readdir_r (on RH 6.2 and 7.2 at least) is NOT like the POSIX
|
|
||||||
// version. Here is the doc for this function:
|
|
||||||
// http://www.gnu.org/manual/glibc-2.2.3/html_node/libc_262.html
|
|
||||||
|
|
||||||
if((status = ::readdir_r(dirp, dbuf, &p)) != 0) {
|
|
||||||
errno = status;
|
|
||||||
return NULL;
|
|
||||||
} else
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int os::closedir(DIR *dirp) {
|
|
||||||
assert(dirp != NULL, "argument is NULL");
|
|
||||||
return ::closedir(dirp);
|
|
||||||
}
|
|
||||||
|
|
||||||
// macros for restartable system calls
|
// macros for restartable system calls
|
||||||
|
|
||||||
#define RESTARTABLE(_cmd, _result) do { \
|
#define RESTARTABLE(_cmd, _result) do { \
|
||||||
|
|
|
@ -535,9 +535,8 @@ static char* get_user_name_slow(int vmid, TRAPS) {
|
||||||
// to determine the user name for the process id.
|
// to determine the user name for the process id.
|
||||||
//
|
//
|
||||||
struct dirent* dentry;
|
struct dirent* dentry;
|
||||||
char* tdbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(tmpdirname), mtInternal);
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
while ((dentry = os::readdir(tmpdirp, (struct dirent *)tdbuf)) != NULL) {
|
while ((dentry = os::readdir(tmpdirp)) != NULL) {
|
||||||
|
|
||||||
// check if the directory entry is a hsperfdata file
|
// check if the directory entry is a hsperfdata file
|
||||||
if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) {
|
if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) {
|
||||||
|
@ -559,9 +558,8 @@ static char* get_user_name_slow(int vmid, TRAPS) {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct dirent* udentry;
|
struct dirent* udentry;
|
||||||
char* udbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(usrdir_name), mtInternal);
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
while ((udentry = os::readdir(subdirp, (struct dirent *)udbuf)) != NULL) {
|
while ((udentry = os::readdir(subdirp)) != NULL) {
|
||||||
|
|
||||||
if (filename_to_pid(udentry->d_name) == vmid) {
|
if (filename_to_pid(udentry->d_name) == vmid) {
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
|
@ -605,11 +603,9 @@ static char* get_user_name_slow(int vmid, TRAPS) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
os::closedir(subdirp);
|
os::closedir(subdirp);
|
||||||
FREE_C_HEAP_ARRAY(char, udbuf);
|
|
||||||
FREE_C_HEAP_ARRAY(char, usrdir_name);
|
FREE_C_HEAP_ARRAY(char, usrdir_name);
|
||||||
}
|
}
|
||||||
os::closedir(tmpdirp);
|
os::closedir(tmpdirp);
|
||||||
FREE_C_HEAP_ARRAY(char, tdbuf);
|
|
||||||
|
|
||||||
return(oldest_user);
|
return(oldest_user);
|
||||||
}
|
}
|
||||||
|
@ -688,10 +684,8 @@ static void cleanup_sharedmem_resources(const char* dirname) {
|
||||||
// opendir/readdir.
|
// opendir/readdir.
|
||||||
//
|
//
|
||||||
struct dirent* entry;
|
struct dirent* entry;
|
||||||
char* dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(dirname), mtInternal);
|
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
while ((entry = os::readdir(dirp, (struct dirent *)dbuf)) != NULL) {
|
while ((entry = os::readdir(dirp)) != NULL) {
|
||||||
|
|
||||||
pid_t pid = filename_to_pid(entry->d_name);
|
pid_t pid = filename_to_pid(entry->d_name);
|
||||||
|
|
||||||
|
@ -730,8 +724,6 @@ static void cleanup_sharedmem_resources(const char* dirname) {
|
||||||
|
|
||||||
// close the directory and reset the current working directory
|
// close the directory and reset the current working directory
|
||||||
close_directory_secure_cwd(dirp, saved_cwd_fd);
|
close_directory_secure_cwd(dirp, saved_cwd_fd);
|
||||||
|
|
||||||
FREE_C_HEAP_ARRAY(char, dbuf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// make the user specific temporary directory. Returns true if
|
// make the user specific temporary directory. Returns true if
|
||||||
|
|
|
@ -5375,8 +5375,7 @@ bool os::dir_is_empty(const char* path) {
|
||||||
|
|
||||||
// Scan the directory
|
// Scan the directory
|
||||||
bool result = true;
|
bool result = true;
|
||||||
char buf[sizeof(struct dirent) + MAX_PATH];
|
while (result && (ptr = readdir(dir)) != NULL) {
|
||||||
while (result && (ptr = ::readdir(dir)) != NULL) {
|
|
||||||
if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
|
if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,17 +69,6 @@ inline void os::dll_unload(void *lib) {
|
||||||
|
|
||||||
inline const int os::default_file_open_flags() { return 0;}
|
inline const int os::default_file_open_flags() { return 0;}
|
||||||
|
|
||||||
inline DIR* os::opendir(const char* dirname)
|
|
||||||
{
|
|
||||||
assert(dirname != NULL, "just checking");
|
|
||||||
return ::opendir(dirname);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int os::readdir_buf_size(const char *path)
|
|
||||||
{
|
|
||||||
return NAME_MAX + sizeof(dirent) + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline jlong os::lseek(int fd, jlong offset, int whence) {
|
inline jlong os::lseek(int fd, jlong offset, int whence) {
|
||||||
return (jlong) ::lseek64(fd, offset, whence);
|
return (jlong) ::lseek64(fd, offset, whence);
|
||||||
}
|
}
|
||||||
|
@ -92,17 +81,6 @@ inline int os::ftruncate(int fd, jlong length) {
|
||||||
return ::ftruncate64(fd, length);
|
return ::ftruncate64(fd, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf)
|
|
||||||
{
|
|
||||||
assert(dirp != NULL, "just checking");
|
|
||||||
return ::readdir(dirp);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int os::closedir(DIR *dirp) {
|
|
||||||
assert(dirp != NULL, "argument is NULL");
|
|
||||||
return ::closedir(dirp);
|
|
||||||
}
|
|
||||||
|
|
||||||
// macros for restartable system calls
|
// macros for restartable system calls
|
||||||
|
|
||||||
#define RESTARTABLE(_cmd, _result) do { \
|
#define RESTARTABLE(_cmd, _result) do { \
|
||||||
|
|
|
@ -895,21 +895,14 @@ int SystemProcessInterface::SystemProcesses::ProcessIterator::current(SystemProc
|
||||||
}
|
}
|
||||||
|
|
||||||
int SystemProcessInterface::SystemProcesses::ProcessIterator::next_process() {
|
int SystemProcessInterface::SystemProcesses::ProcessIterator::next_process() {
|
||||||
struct dirent* entry;
|
|
||||||
|
|
||||||
if (!is_valid()) {
|
if (!is_valid()) {
|
||||||
return OS_ERR;
|
return OS_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
entry = os::readdir(_dir, _entry);
|
_entry = os::readdir(_dir);
|
||||||
if (entry == NULL) {
|
|
||||||
// error
|
|
||||||
_valid = false;
|
|
||||||
return OS_ERR;
|
|
||||||
}
|
|
||||||
if (_entry == NULL) {
|
if (_entry == NULL) {
|
||||||
// reached end
|
// Error or reached end. Could use errno to distinguish those cases.
|
||||||
_valid = false;
|
_valid = false;
|
||||||
return OS_ERR;
|
return OS_ERR;
|
||||||
}
|
}
|
||||||
|
@ -926,11 +919,8 @@ SystemProcessInterface::SystemProcesses::ProcessIterator::ProcessIterator() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SystemProcessInterface::SystemProcesses::ProcessIterator::initialize() {
|
bool SystemProcessInterface::SystemProcesses::ProcessIterator::initialize() {
|
||||||
_dir = opendir("/proc");
|
_dir = os::opendir("/proc");
|
||||||
_entry = (struct dirent*)NEW_C_HEAP_ARRAY(char, sizeof(struct dirent) + NAME_MAX + 1, mtInternal);
|
_entry = NULL;
|
||||||
if (NULL == _entry) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
_valid = true;
|
_valid = true;
|
||||||
next_process();
|
next_process();
|
||||||
|
|
||||||
|
@ -938,11 +928,8 @@ bool SystemProcessInterface::SystemProcesses::ProcessIterator::initialize() {
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemProcessInterface::SystemProcesses::ProcessIterator::~ProcessIterator() {
|
SystemProcessInterface::SystemProcesses::ProcessIterator::~ProcessIterator() {
|
||||||
if (_entry != NULL) {
|
|
||||||
FREE_C_HEAP_ARRAY(char, _entry);
|
|
||||||
}
|
|
||||||
if (_dir != NULL) {
|
if (_dir != NULL) {
|
||||||
closedir(_dir);
|
os::closedir(_dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -561,9 +561,8 @@ static char* get_user_name_slow(int vmid, int nspid, TRAPS) {
|
||||||
// to determine the user name for the process id.
|
// to determine the user name for the process id.
|
||||||
//
|
//
|
||||||
struct dirent* dentry;
|
struct dirent* dentry;
|
||||||
char* tdbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(tmpdirname), mtInternal);
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
while ((dentry = os::readdir(tmpdirp, (struct dirent *)tdbuf)) != NULL) {
|
while ((dentry = os::readdir(tmpdirp)) != NULL) {
|
||||||
|
|
||||||
// check if the directory entry is a hsperfdata file
|
// check if the directory entry is a hsperfdata file
|
||||||
if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) {
|
if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) {
|
||||||
|
@ -597,9 +596,8 @@ static char* get_user_name_slow(int vmid, int nspid, TRAPS) {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct dirent* udentry;
|
struct dirent* udentry;
|
||||||
char* udbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(usrdir_name), mtInternal);
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
while ((udentry = os::readdir(subdirp, (struct dirent *)udbuf)) != NULL) {
|
while ((udentry = os::readdir(subdirp)) != NULL) {
|
||||||
|
|
||||||
if (filename_to_pid(udentry->d_name) == searchpid) {
|
if (filename_to_pid(udentry->d_name) == searchpid) {
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
|
@ -643,11 +641,9 @@ static char* get_user_name_slow(int vmid, int nspid, TRAPS) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
os::closedir(subdirp);
|
os::closedir(subdirp);
|
||||||
FREE_C_HEAP_ARRAY(char, udbuf);
|
|
||||||
FREE_C_HEAP_ARRAY(char, usrdir_name);
|
FREE_C_HEAP_ARRAY(char, usrdir_name);
|
||||||
}
|
}
|
||||||
os::closedir(tmpdirp);
|
os::closedir(tmpdirp);
|
||||||
FREE_C_HEAP_ARRAY(char, tdbuf);
|
|
||||||
|
|
||||||
return(oldest_user);
|
return(oldest_user);
|
||||||
}
|
}
|
||||||
|
@ -769,10 +765,8 @@ static void cleanup_sharedmem_resources(const char* dirname) {
|
||||||
// opendir/readdir.
|
// opendir/readdir.
|
||||||
//
|
//
|
||||||
struct dirent* entry;
|
struct dirent* entry;
|
||||||
char* dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(dirname), mtInternal);
|
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
while ((entry = os::readdir(dirp, (struct dirent *)dbuf)) != NULL) {
|
while ((entry = os::readdir(dirp)) != NULL) {
|
||||||
|
|
||||||
pid_t pid = filename_to_pid(entry->d_name);
|
pid_t pid = filename_to_pid(entry->d_name);
|
||||||
|
|
||||||
|
@ -809,8 +803,6 @@ static void cleanup_sharedmem_resources(const char* dirname) {
|
||||||
|
|
||||||
// close the directory and reset the current working directory
|
// close the directory and reset the current working directory
|
||||||
close_directory_secure_cwd(dirp, saved_cwd_fd);
|
close_directory_secure_cwd(dirp, saved_cwd_fd);
|
||||||
|
|
||||||
FREE_C_HEAP_ARRAY(char, dbuf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// make the user specific temporary directory. Returns true if
|
// make the user specific temporary directory. Returns true if
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include "utilities/macros.hpp"
|
#include "utilities/macros.hpp"
|
||||||
#include "utilities/vmError.hpp"
|
#include "utilities/vmError.hpp"
|
||||||
|
|
||||||
|
#include <dirent.h>
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
@ -527,6 +528,21 @@ void os::funlockfile(FILE* fp) {
|
||||||
::funlockfile(fp);
|
::funlockfile(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DIR* os::opendir(const char* dirname) {
|
||||||
|
assert(dirname != NULL, "just checking");
|
||||||
|
return ::opendir(dirname);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct dirent* os::readdir(DIR* dirp) {
|
||||||
|
assert(dirp != NULL, "just checking");
|
||||||
|
return ::readdir(dirp);
|
||||||
|
}
|
||||||
|
|
||||||
|
int os::closedir(DIR *dirp) {
|
||||||
|
assert(dirp != NULL, "just checking");
|
||||||
|
return ::closedir(dirp);
|
||||||
|
}
|
||||||
|
|
||||||
// Builds a platform dependent Agent_OnLoad_<lib_name> function name
|
// Builds a platform dependent Agent_OnLoad_<lib_name> function name
|
||||||
// which is used to find statically linked in agents.
|
// which is used to find statically linked in agents.
|
||||||
// Parameters:
|
// Parameters:
|
||||||
|
|
|
@ -604,15 +604,14 @@ int SystemProcessInterface::SystemProcesses::ProcessIterator::current(SystemProc
|
||||||
}
|
}
|
||||||
|
|
||||||
int SystemProcessInterface::SystemProcesses::ProcessIterator::next_process() {
|
int SystemProcessInterface::SystemProcesses::ProcessIterator::next_process() {
|
||||||
struct dirent* entry;
|
|
||||||
|
|
||||||
if (!is_valid()) {
|
if (!is_valid()) {
|
||||||
return OS_ERR;
|
return OS_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if ((entry = os::readdir(_dir, _entry)) == NULL) {
|
_entry = os::readdir(_dir);
|
||||||
// error
|
if (_entry == NULL) {
|
||||||
|
// Error or reached end. Could use errno to distinguish those cases.
|
||||||
_valid = false;
|
_valid = false;
|
||||||
return OS_ERR;
|
return OS_ERR;
|
||||||
}
|
}
|
||||||
|
@ -629,11 +628,8 @@ SystemProcessInterface::SystemProcesses::ProcessIterator::ProcessIterator() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SystemProcessInterface::SystemProcesses::ProcessIterator::initialize() {
|
bool SystemProcessInterface::SystemProcesses::ProcessIterator::initialize() {
|
||||||
_dir = opendir("/proc");
|
_dir = os::opendir("/proc");
|
||||||
_entry = (struct dirent*)NEW_C_HEAP_ARRAY(char, sizeof(struct dirent) + _PC_NAME_MAX + 1, mtInternal);
|
_entry = NULL;
|
||||||
if (NULL == _entry) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
_valid = true;
|
_valid = true;
|
||||||
next_process();
|
next_process();
|
||||||
|
|
||||||
|
@ -641,12 +637,8 @@ bool SystemProcessInterface::SystemProcesses::ProcessIterator::initialize() {
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemProcessInterface::SystemProcesses::ProcessIterator::~ProcessIterator() {
|
SystemProcessInterface::SystemProcesses::ProcessIterator::~ProcessIterator() {
|
||||||
if (_entry != NULL) {
|
|
||||||
FREE_C_HEAP_ARRAY(char, _entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_dir != NULL) {
|
if (_dir != NULL) {
|
||||||
closedir(_dir);
|
os::closedir(_dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4308,9 +4308,7 @@ bool os::dir_is_empty(const char* path) {
|
||||||
|
|
||||||
// Scan the directory
|
// Scan the directory
|
||||||
bool result = true;
|
bool result = true;
|
||||||
char buf[sizeof(struct dirent) + MAX_PATH];
|
while (result && (ptr = readdir(dir)) != NULL) {
|
||||||
struct dirent *dbuf = (struct dirent *) buf;
|
|
||||||
while (result && (ptr = readdir(dir, dbuf)) != NULL) {
|
|
||||||
if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
|
if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,34 +68,6 @@ inline void os::dll_unload(void *lib) { ::dlclose(lib); }
|
||||||
|
|
||||||
inline const int os::default_file_open_flags() { return 0;}
|
inline const int os::default_file_open_flags() { return 0;}
|
||||||
|
|
||||||
inline DIR* os::opendir(const char* dirname) {
|
|
||||||
assert(dirname != NULL, "just checking");
|
|
||||||
return ::opendir(dirname);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int os::readdir_buf_size(const char *path) {
|
|
||||||
int size = pathconf(path, _PC_NAME_MAX);
|
|
||||||
return (size < 0 ? MAXPATHLEN : size) + sizeof(dirent) + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline struct dirent* os::readdir(DIR* dirp, dirent* dbuf) {
|
|
||||||
assert(dirp != NULL, "just checking");
|
|
||||||
dirent* p;
|
|
||||||
int status;
|
|
||||||
|
|
||||||
if((status = ::readdir_r(dirp, dbuf, &p)) != 0) {
|
|
||||||
errno = status;
|
|
||||||
return NULL;
|
|
||||||
} else {
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int os::closedir(DIR *dirp) {
|
|
||||||
assert(dirp != NULL, "argument is NULL");
|
|
||||||
return ::closedir(dirp);
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
|
@ -523,9 +523,8 @@ static char* get_user_name_slow(int vmid, TRAPS) {
|
||||||
// to determine the user name for the process id.
|
// to determine the user name for the process id.
|
||||||
//
|
//
|
||||||
struct dirent* dentry;
|
struct dirent* dentry;
|
||||||
char* tdbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(tmpdirname), mtInternal);
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
while ((dentry = os::readdir(tmpdirp, (struct dirent *)tdbuf)) != NULL) {
|
while ((dentry = os::readdir(tmpdirp)) != NULL) {
|
||||||
|
|
||||||
// check if the directory entry is a hsperfdata file
|
// check if the directory entry is a hsperfdata file
|
||||||
if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) {
|
if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) {
|
||||||
|
@ -559,9 +558,8 @@ static char* get_user_name_slow(int vmid, TRAPS) {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct dirent* udentry;
|
struct dirent* udentry;
|
||||||
char* udbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(usrdir_name), mtInternal);
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
while ((udentry = os::readdir(subdirp, (struct dirent *)udbuf)) != NULL) {
|
while ((udentry = os::readdir(subdirp)) != NULL) {
|
||||||
|
|
||||||
if (filename_to_pid(udentry->d_name) == vmid) {
|
if (filename_to_pid(udentry->d_name) == vmid) {
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
|
@ -605,11 +603,9 @@ static char* get_user_name_slow(int vmid, TRAPS) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
os::closedir(subdirp);
|
os::closedir(subdirp);
|
||||||
FREE_C_HEAP_ARRAY(char, udbuf);
|
|
||||||
FREE_C_HEAP_ARRAY(char, usrdir_name);
|
FREE_C_HEAP_ARRAY(char, usrdir_name);
|
||||||
}
|
}
|
||||||
os::closedir(tmpdirp);
|
os::closedir(tmpdirp);
|
||||||
FREE_C_HEAP_ARRAY(char, tdbuf);
|
|
||||||
|
|
||||||
return(oldest_user);
|
return(oldest_user);
|
||||||
}
|
}
|
||||||
|
@ -736,10 +732,8 @@ static void cleanup_sharedmem_resources(const char* dirname) {
|
||||||
// opendir/readdir.
|
// opendir/readdir.
|
||||||
//
|
//
|
||||||
struct dirent* entry;
|
struct dirent* entry;
|
||||||
char* dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(dirname), mtInternal);
|
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
while ((entry = os::readdir(dirp, (struct dirent *)dbuf)) != NULL) {
|
while ((entry = os::readdir(dirp)) != NULL) {
|
||||||
|
|
||||||
pid_t pid = filename_to_pid(entry->d_name);
|
pid_t pid = filename_to_pid(entry->d_name);
|
||||||
|
|
||||||
|
@ -778,8 +772,6 @@ static void cleanup_sharedmem_resources(const char* dirname) {
|
||||||
|
|
||||||
// close the directory and reset the current working directory
|
// close the directory and reset the current working directory
|
||||||
close_directory_secure_cwd(dirp, saved_cwd_fd);
|
close_directory_secure_cwd(dirp, saved_cwd_fd);
|
||||||
|
|
||||||
FREE_C_HEAP_ARRAY(char, dbuf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// make the user specific temporary directory. Returns true if
|
// make the user specific temporary directory. Returns true if
|
||||||
|
|
|
@ -1170,11 +1170,10 @@ DIR * os::opendir(const char *dirname) {
|
||||||
return dirp;
|
return dirp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// parameter dbuf unused on Windows
|
struct dirent * os::readdir(DIR *dirp) {
|
||||||
struct dirent * os::readdir(DIR *dirp, dirent *dbuf) {
|
|
||||||
assert(dirp != NULL, "just checking"); // hotspot change
|
assert(dirp != NULL, "just checking"); // hotspot change
|
||||||
if (dirp->handle == INVALID_HANDLE_VALUE) {
|
if (dirp->handle == INVALID_HANDLE_VALUE) {
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(dirp->dirent.d_name, dirp->find_data.cFileName);
|
strcpy(dirp->dirent.d_name, dirp->find_data.cFileName);
|
||||||
|
@ -1182,7 +1181,7 @@ struct dirent * os::readdir(DIR *dirp, dirent *dbuf) {
|
||||||
if (!FindNextFile(dirp->handle, &dirp->find_data)) {
|
if (!FindNextFile(dirp->handle, &dirp->find_data)) {
|
||||||
if (GetLastError() == ERROR_INVALID_HANDLE) {
|
if (GetLastError() == ERROR_INVALID_HANDLE) {
|
||||||
errno = EBADF;
|
errno = EBADF;
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
FindClose(dirp->handle);
|
FindClose(dirp->handle);
|
||||||
dirp->handle = INVALID_HANDLE_VALUE;
|
dirp->handle = INVALID_HANDLE_VALUE;
|
||||||
|
|
|
@ -57,14 +57,6 @@ inline bool os::must_commit_stack_guard_pages() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int os::readdir_buf_size(const char *path)
|
|
||||||
{
|
|
||||||
/* As Windows doesn't use the directory entry buffer passed to
|
|
||||||
os::readdir() this can be as short as possible */
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bang the shadow pages if they need to be touched to be mapped.
|
// Bang the shadow pages if they need to be touched to be mapped.
|
||||||
inline void os::map_stack_shadow_pages(address sp) {
|
inline void os::map_stack_shadow_pages(address sp) {
|
||||||
// Write to each page of our new frame to force OS mapping.
|
// Write to each page of our new frame to force OS mapping.
|
||||||
|
|
|
@ -318,9 +318,8 @@ static char* get_user_name_slow(int vmid) {
|
||||||
// to determine the user name for the process id.
|
// to determine the user name for the process id.
|
||||||
//
|
//
|
||||||
struct dirent* dentry;
|
struct dirent* dentry;
|
||||||
char* tdbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(tmpdirname), mtInternal);
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
while ((dentry = os::readdir(tmpdirp, (struct dirent *)tdbuf)) != NULL) {
|
while ((dentry = os::readdir(tmpdirp)) != NULL) {
|
||||||
|
|
||||||
// check if the directory entry is a hsperfdata file
|
// check if the directory entry is a hsperfdata file
|
||||||
if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) {
|
if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) {
|
||||||
|
@ -353,9 +352,8 @@ static char* get_user_name_slow(int vmid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct dirent* udentry;
|
struct dirent* udentry;
|
||||||
char* udbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(usrdir_name), mtInternal);
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
while ((udentry = os::readdir(subdirp, (struct dirent *)udbuf)) != NULL) {
|
while ((udentry = os::readdir(subdirp)) != NULL) {
|
||||||
|
|
||||||
if (filename_to_pid(udentry->d_name) == vmid) {
|
if (filename_to_pid(udentry->d_name) == vmid) {
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
|
@ -407,11 +405,9 @@ static char* get_user_name_slow(int vmid) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
os::closedir(subdirp);
|
os::closedir(subdirp);
|
||||||
FREE_C_HEAP_ARRAY(char, udbuf);
|
|
||||||
FREE_C_HEAP_ARRAY(char, usrdir_name);
|
FREE_C_HEAP_ARRAY(char, usrdir_name);
|
||||||
}
|
}
|
||||||
os::closedir(tmpdirp);
|
os::closedir(tmpdirp);
|
||||||
FREE_C_HEAP_ARRAY(char, tdbuf);
|
|
||||||
|
|
||||||
return(latest_user);
|
return(latest_user);
|
||||||
}
|
}
|
||||||
|
@ -642,9 +638,8 @@ static void cleanup_sharedmem_resources(const char* dirname) {
|
||||||
// opendir/readdir.
|
// opendir/readdir.
|
||||||
//
|
//
|
||||||
struct dirent* entry;
|
struct dirent* entry;
|
||||||
char* dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(dirname), mtInternal);
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
while ((entry = os::readdir(dirp, (struct dirent *)dbuf)) != NULL) {
|
while ((entry = os::readdir(dirp)) != NULL) {
|
||||||
|
|
||||||
int pid = filename_to_pid(entry->d_name);
|
int pid = filename_to_pid(entry->d_name);
|
||||||
|
|
||||||
|
@ -685,7 +680,6 @@ static void cleanup_sharedmem_resources(const char* dirname) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
}
|
}
|
||||||
os::closedir(dirp);
|
os::closedir(dirp);
|
||||||
FREE_C_HEAP_ARRAY(char, dbuf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a file mapping object with the requested name, and size
|
// create a file mapping object with the requested name, and size
|
||||||
|
|
|
@ -241,11 +241,7 @@ RepositoryIterator::RepositoryIterator(const char* repository, size_t repository
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
struct dirent* dentry;
|
struct dirent* dentry;
|
||||||
char* dir_buffer = NEW_RESOURCE_ARRAY_RETURN_NULL(char, os::readdir_buf_size(_repo));
|
while ((dentry = os::readdir(dirp)) != NULL) {
|
||||||
if (dir_buffer == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
while ((dentry = os::readdir(dirp, (struct dirent*)dir_buffer)) != NULL) {
|
|
||||||
const char* const entry_path = filter(dentry->d_name);
|
const char* const entry_path = filter(dentry->d_name);
|
||||||
if (NULL != entry_path) {
|
if (NULL != entry_path) {
|
||||||
_files->append(entry_path);
|
_files->append(entry_path);
|
||||||
|
|
|
@ -580,8 +580,7 @@ class os: AllStatic {
|
||||||
|
|
||||||
// Reading directories.
|
// Reading directories.
|
||||||
static DIR* opendir(const char* dirname);
|
static DIR* opendir(const char* dirname);
|
||||||
static int readdir_buf_size(const char *path);
|
static struct dirent* readdir(DIR* dirp);
|
||||||
static struct dirent* readdir(DIR* dirp, dirent* dbuf);
|
|
||||||
static int closedir(DIR* dirp);
|
static int closedir(DIR* dirp);
|
||||||
|
|
||||||
// Dynamic library extension
|
// Dynamic library extension
|
||||||
|
|
|
@ -873,4 +873,3 @@ com/sun/jdi/RedefineCrossEvent.java 8194308 gener
|
||||||
|
|
||||||
jdk/jfr/event/io/TestInstrumentation.java 8202142 generic-all
|
jdk/jfr/event/io/TestInstrumentation.java 8202142 generic-all
|
||||||
jdk/jfr/event/sampling/TestNative.java 8202142 generic-all
|
jdk/jfr/event/sampling/TestNative.java 8202142 generic-all
|
||||||
jdk/jfr/event/os/TestSystemProcess.java 8202835 linux-all
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue