# HG changeset patch # User igerasim # Date 1552583467 25200 # Thu Mar 14 10:11:07 2019 -0700 # Node ID 909ec046a11ca4aee35bab61734fbb3ec1b5b595 # Parent 641768acb12ea1bc46fd25d9c6d4f38ffcd9cc92 imported patch 6307456-UnixFileSystem_md-c-use-of-chmod-and-access-should-handle-EINTR-signal-appropriately-unix diff --git a/src/java.base/unix/native/libjava/UnixFileSystem_md.c b/src/java.base/unix/native/libjava/UnixFileSystem_md.c --- a/src/java.base/unix/native/libjava/UnixFileSystem_md.c +++ b/src/java.base/unix/native/libjava/UnixFileSystem_md.c @@ -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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ struct statfs fsstat; #else struct statvfs64 fsstat; + int res; #endif memset(&fsstat, 0, sizeof(fsstat)); #ifdef MACOSX @@ -488,7 +497,8 @@ } } #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), diff --git a/src/java.base/unix/native/libjava/io_util_md.h b/src/java.base/unix/native/libjava/io_util_md.h --- a/src/java.base/unix/native/libjava/io_util_md.h +++ b/src/java.base/unix/native/libjava/io_util_md.h @@ -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 @@ /* * 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);