mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 23:34:52 +02:00
6307456: UnixFileSystem_md.c use of chmod() and access() should handle EINTR signal appropriately (unix)
Reviewed-by: bpb, dholmes, alanb
This commit is contained in:
parent
8743be63c4
commit
07b560a1a1
2 changed files with 27 additions and 18 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1998, 2019, 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
|
||||
|
@ -168,7 +168,9 @@ Java_java_io_UnixFileSystem_checkAccess(JNIEnv *env, jobject this,
|
|||
default: assert(0);
|
||||
}
|
||||
WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
|
||||
if (access(path, mode) == 0) {
|
||||
int res;
|
||||
RESTARTABLE(access(path, mode), res);
|
||||
if (res == 0) {
|
||||
rv = JNI_TRUE;
|
||||
}
|
||||
} END_PLATFORM_STRING(env, path);
|
||||
|
@ -188,6 +190,7 @@ Java_java_io_UnixFileSystem_setPermission(JNIEnv *env, jobject this,
|
|||
WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
|
||||
int amode = 0;
|
||||
int mode;
|
||||
int res;
|
||||
switch (access) {
|
||||
case java_io_FileSystem_ACCESS_READ:
|
||||
if (owneronly)
|
||||
|
@ -215,7 +218,8 @@ Java_java_io_UnixFileSystem_setPermission(JNIEnv *env, jobject this,
|
|||
mode |= amode;
|
||||
else
|
||||
mode &= ~amode;
|
||||
if (chmod(path, mode) >= 0) {
|
||||
RESTARTABLE(chmod(path, mode), res);
|
||||
if (res == 0) {
|
||||
rv = JNI_TRUE;
|
||||
}
|
||||
}
|
||||
|
@ -355,13 +359,15 @@ Java_java_io_UnixFileSystem_list(JNIEnv *env, jobject this,
|
|||
closedir(dir);
|
||||
|
||||
/* Copy the final results into an appropriately-sized array */
|
||||
old = rv;
|
||||
rv = (*env)->NewObjectArray(env, len, str_class, NULL);
|
||||
if (rv == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (JNU_CopyObjectArray(env, rv, old, len) < 0) {
|
||||
return NULL;
|
||||
if (len < maxlen) {
|
||||
old = rv;
|
||||
rv = (*env)->NewObjectArray(env, len, str_class, NULL);
|
||||
if (rv == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (JNU_CopyObjectArray(env, rv, old, len) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
|
||||
|
@ -446,8 +452,10 @@ Java_java_io_UnixFileSystem_setReadOnly(JNIEnv *env, jobject this,
|
|||
|
||||
WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
|
||||
int mode;
|
||||
int res;
|
||||
if (statMode(path, &mode)) {
|
||||
if (chmod(path, mode & ~(S_IWUSR | S_IWGRP | S_IWOTH)) >= 0) {
|
||||
RESTARTABLE(chmod(path, mode & ~(S_IWUSR | S_IWGRP | S_IWOTH)), res);
|
||||
if (res == 0) {
|
||||
rv = JNI_TRUE;
|
||||
}
|
||||
}
|
||||
|
@ -466,6 +474,7 @@ Java_java_io_UnixFileSystem_getSpace(JNIEnv *env, jobject this,
|
|||
struct statfs fsstat;
|
||||
#else
|
||||
struct statvfs64 fsstat;
|
||||
int res;
|
||||
#endif
|
||||
memset(&fsstat, 0, sizeof(fsstat));
|
||||
#ifdef MACOSX
|
||||
|
@ -488,7 +497,8 @@ Java_java_io_UnixFileSystem_getSpace(JNIEnv *env, jobject this,
|
|||
}
|
||||
}
|
||||
#else
|
||||
if (statvfs64(path, &fsstat) == 0) {
|
||||
RESTARTABLE(statvfs64(path, &fsstat), res);
|
||||
if (res == 0) {
|
||||
switch(t) {
|
||||
case java_io_FileSystem_SPACE_TOTAL:
|
||||
rv = jlong_mul(long_to_jlong(fsstat.f_frsize),
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2019, 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
|
||||
|
@ -93,11 +93,10 @@ FD handleOpen(const char *path, int oflag, int mode);
|
|||
/*
|
||||
* Retry the operation if it is interrupted
|
||||
*/
|
||||
#define RESTARTABLE(_cmd, _result) do { \
|
||||
do { \
|
||||
_result = _cmd; \
|
||||
} while((_result == -1) && (errno == EINTR)); \
|
||||
} while(0)
|
||||
#define RESTARTABLE(_cmd, _result) \
|
||||
do { \
|
||||
_result = _cmd; \
|
||||
} while ((_result == -1) && (errno == EINTR))
|
||||
|
||||
void fileDescriptorClose(JNIEnv *env, jobject this);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue