On 4 May 2018 at 17:42, Alan Bateman <alan.bate...@oracle.com> wrote:
> On 04/05/2018 16:31, B. Blaser wrote:
>>
>> :
>>
>> I'll create a new JBS issue (unless you want to) since the fix is
>> mostly located in core-libs and only intended to make the build
>> complete.
>> But I'll still need someone to review and push the fix, would you be
>> interested in doing this?
>>
> I think someone needs to explore the behavior on other platforms too as the
> #ifndef __linux__ patches are ugly.

Yes sure but I cannot test it elsewhere myself... and we can easily
remove them once POSIX officially deprecates 'readdir_r' or if someone
validates the fix on other systems.

> Is there discussion on the original
> thread about this?

As Kim said, JDK-8202353 summarize the situation.

> -Alan

I've just made a small improvement (below) using 'errno' to preserve
the exact behavior when necessary, what do yo think?

Bernard

diff -r 1871c5d07caf src/java.base/unix/native/libjava/TimeZone_md.c
--- a/src/java.base/unix/native/libjava/TimeZone_md.c    Fri Apr 27
15:55:29 2018 -0700
+++ b/src/java.base/unix/native/libjava/TimeZone_md.c    Sat May 05
12:54:56 2018 +0200
@@ -122,7 +122,9 @@
     DIR *dirp = NULL;
     struct stat statbuf;
     struct dirent64 *dp = NULL;
+#ifndef __linux__
     struct dirent64 *entry = NULL;
+#endif
     char *pathname = NULL;
     int fd = -1;
     char *dbuf = NULL;
@@ -140,7 +142,7 @@
     if (name_max < 1024) {
         name_max = 1024;
     }
-
+#ifndef __linux__
     entry = (struct dirent64 *)malloc(offsetof(struct dirent64,
d_name) + name_max + 1);
     if (entry == NULL) {
         (void) closedir(dirp);
@@ -148,6 +150,9 @@
     }

     while (readdir64_r(dirp, entry, &dp) == 0 && dp != NULL) {
+#else
+    while ((dp = readdir64(dirp)) != NULL) {
+#endif
         /*
          * Skip '.' and '..' (and possibly other .* files)
          */
@@ -213,10 +218,11 @@
         free((void *) pathname);
         pathname = NULL;
     }
-
+#ifndef __linux__
     if (entry != NULL) {
         free((void *) entry);
     }
+#endif
     if (dirp != NULL) {
         (void) closedir(dirp);
     }
diff -r 1871c5d07caf src/java.base/unix/native/libjava/UnixFileSystem_md.c
--- a/src/java.base/unix/native/libjava/UnixFileSystem_md.c    Fri Apr
27 15:55:29 2018 -0700
+++ b/src/java.base/unix/native/libjava/UnixFileSystem_md.c    Sat May
05 12:54:56 2018 +0200
@@ -312,7 +312,9 @@
 {
     DIR *dir = NULL;
     struct dirent64 *ptr;
+#ifndef __linux__
     struct dirent64 *result;
+#endif
     int len, maxlen;
     jobjectArray rv, old;
     jclass str_class;
@@ -324,14 +326,14 @@
         dir = opendir(path);
     } END_PLATFORM_STRING(env, path);
     if (dir == NULL) return NULL;
-
+#ifndef __linux__
     ptr = malloc(sizeof(struct dirent64) + (PATH_MAX + 1));
     if (ptr == NULL) {
         JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
         closedir(dir);
         return NULL;
     }
-
+#endif
     /* Allocate an initial String array */
     len = 0;
     maxlen = 16;
@@ -339,7 +341,11 @@
     if (rv == NULL) goto error;

     /* Scan the directory */
+#ifndef __linux__
     while ((readdir64_r(dir, ptr, &result) == 0)  && (result != NULL)) {
+#else
+    while ((ptr = readdir64(dir)) != NULL) {
+#endif
         jstring name;
         if (!strcmp(ptr->d_name, ".") || !strcmp(ptr->d_name, ".."))
             continue;
@@ -360,7 +366,9 @@
         (*env)->DeleteLocalRef(env, name);
     }
     closedir(dir);
+#ifndef __linux__
     free(ptr);
+#endif

     /* Copy the final results into an appropriately-sized array */
     old = rv;
@@ -375,7 +383,9 @@

  error:
     closedir(dir);
+#ifndef __linux__
     free(ptr);
+#endif
     return NULL;
 }

diff -r 1871c5d07caf src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
--- a/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
Fri Apr 27 15:55:29 2018 -0700
+++ b/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
Sat May 05 12:54:56 2018 +0200
@@ -726,12 +726,19 @@
         char name_extra[PATH_MAX + 1 - sizeof result->d_name];
     } entry;
     struct dirent64* ptr = &entry.buf;
+#ifndef __linux__
     int res;
+#endif
     DIR* dirp = jlong_to_ptr(value);

     /* EINTR not listed as a possible error */
     /* TDB: reentrant version probably not required here */
+#ifndef __linux__
     res = readdir64_r(dirp, ptr, &result);
+#else
+    errno = 0;
+    ptr = result = readdir64(dirp);
+#endif

 #ifdef _AIX
     /* On AIX, readdir_r() returns EBADF (i.e. '9') and sets 'result'
to NULL for the */
@@ -741,8 +748,13 @@
     }
 #endif

+#ifndef __linux__
     if (res != 0) {
         throwUnixException(env, res);
+#else
+    if (errno != 0) {
+        throwUnixException(env, errno);
+#endif
         return NULL;
     } else {
         if (result == NULL) {
diff -r 1871c5d07caf
src/jdk.management/unix/native/libmanagement_ext/OperatingSystemImpl.c
--- a/src/jdk.management/unix/native/libmanagement_ext/OperatingSystemImpl.c
   Fri Apr 27 15:55:29 2018 -0700
+++ b/src/jdk.management/unix/native/libmanagement_ext/OperatingSystemImpl.c
   Sat May 05 12:54:56 2018 +0200
@@ -75,10 +75,10 @@
 #endif /* _ALLBSD_SOURCE */

 static struct dirent* read_dir(DIR* dirp, struct dirent* entry) {
-#ifdef __solaris__
+#if defined(__solaris__) || defined(__linux__)
     struct dirent* dbuf = readdir(dirp);
     return dbuf;
-#else /* __linux__ || _ALLBSD_SOURCE */
+#else /* _ALLBSD_SOURCE */
     struct dirent* p;
     if (readdir_r(dirp, entry, &p) == 0) {
         return p;

Reply via email to