< prev index next >

src/java.base/unix/native/libjava/UnixFileSystem_md.c

Print this page
rev 54131 : imported patch 6307456-UnixFileSystem_md-c-use-of-chmod-and-access-should-handle-EINTR-signal-appropriately-unix

@@ -1,7 +1,7 @@
 /*
- * 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
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -166,11 +166,13 @@
         mode = X_OK;
         break;
     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);
     return rv;
 }

@@ -186,10 +188,11 @@
     jboolean rv = JNI_FALSE;
 
     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)
                 amode = S_IRUSR;
             else

@@ -213,11 +216,12 @@
         if (statMode(path, &mode)) {
             if (enable)
                 mode |= amode;
             else
                 mode &= ~amode;
-            if (chmod(path, mode) >= 0) {
+            RESTARTABLE(chmod(path, mode), res);
+            if (res == 0) {
                 rv = JNI_TRUE;
             }
         }
     } END_PLATFORM_STRING(env, path);
     return rv;

@@ -353,18 +357,20 @@
         (*env)->DeleteLocalRef(env, name);
     }
     closedir(dir);
 
     /* Copy the final results into an appropriately-sized array */
+    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;
 
  error:
     closedir(dir);
     return NULL;

@@ -444,12 +450,14 @@
 {
     jboolean rv = JNI_FALSE;
 
     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;
             }
         }
     } END_PLATFORM_STRING(env, path);
     return rv;

@@ -464,10 +472,11 @@
     WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
 #ifdef MACOSX
         struct statfs fsstat;
 #else
         struct statvfs64 fsstat;
+        int res;
 #endif
         memset(&fsstat, 0, sizeof(fsstat));
 #ifdef MACOSX
         if (statfs(path, &fsstat) == 0) {
             switch(t) {

@@ -486,11 +495,12 @@
                 default:
                     assert(0);
             }
         }
 #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),
                                long_to_jlong(fsstat.f_blocks));
                 break;
< prev index next >