RFR: 8179887 - Build failure with glibc >= 2.24: error: 'int readdir_r(DIR*, dirent*, dirent**)' is deprecated
B. Blaser
bsrbnd at gmail.com
Mon May 7 12:19:14 UTC 2018
On 6 May 2018 at 18:35, B. Blaser <bsrbnd at gmail.com> wrote:
> On 5 May 2018 at 22:26, Kim Barrett <kim.barrett at oracle.com> wrote:
>>> On May 5, 2018, at 8:03 AM, B. Blaser <bsrbnd at gmail.com> wrote:
>>>
>>> On 4 May 2018 at 17:42, Alan Bateman <Alan.Bateman at 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.
>>
>> I'm not sure anyone has the ability to test on all supported. That
>> doesn't (and really can't) prevent making changes across platforms to
>> platform-specific code. It just means one needs to get help with
>> testing. Make the change across platforms, test on those platforms
>> one has access to, and ask here for help testing on others.
>
> OK, I'll provide a cross-platform fix to be evaluated on other systems too.
Here it is, tier1 is successful on Linux with glibc=2.26.
Any feedback on other systems would be very helpful.
Does this look better?
Thanks,
Bernard
diff -r e81481fea884 src/java.base/unix/native/libjava/TimeZone_md.c
--- a/src/java.base/unix/native/libjava/TimeZone_md.c Mon May 07
08:56:35 2018 +0200
+++ b/src/java.base/unix/native/libjava/TimeZone_md.c Mon May 07
12:38:42 2018 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2018, 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
@@ -122,32 +122,18 @@
DIR *dirp = NULL;
struct stat statbuf;
struct dirent64 *dp = NULL;
- struct dirent64 *entry = NULL;
char *pathname = NULL;
int fd = -1;
char *dbuf = NULL;
char *tz = NULL;
int res;
- long name_max = 0;
dirp = opendir(dir);
if (dirp == NULL) {
return NULL;
}
- name_max = pathconf(dir, _PC_NAME_MAX);
- // If pathconf did not work, fall back to a mimimum buffer size.
- if (name_max < 1024) {
- name_max = 1024;
- }
-
- entry = (struct dirent64 *)malloc(offsetof(struct dirent64,
d_name) + name_max + 1);
- if (entry == NULL) {
- (void) closedir(dirp);
- return NULL;
- }
-
- while (readdir64_r(dirp, entry, &dp) == 0 && dp != NULL) {
+ while ((dp = readdir64(dirp)) != NULL) {
/*
* Skip '.' and '..' (and possibly other .* files)
*/
@@ -214,9 +200,6 @@
pathname = NULL;
}
- if (entry != NULL) {
- free((void *) entry);
- }
if (dirp != NULL) {
(void) closedir(dirp);
}
diff -r e81481fea884 src/java.base/unix/native/libjava/UnixFileSystem_md.c
--- a/src/java.base/unix/native/libjava/UnixFileSystem_md.c Mon May
07 08:56:35 2018 +0200
+++ b/src/java.base/unix/native/libjava/UnixFileSystem_md.c Mon May
07 12:38:42 2018 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2018, 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
@@ -312,7 +312,6 @@
{
DIR *dir = NULL;
struct dirent64 *ptr;
- struct dirent64 *result;
int len, maxlen;
jobjectArray rv, old;
jclass str_class;
@@ -325,13 +324,6 @@
} END_PLATFORM_STRING(env, path);
if (dir == NULL) return NULL;
- ptr = malloc(sizeof(struct dirent64) + (PATH_MAX + 1));
- if (ptr == NULL) {
- JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
- closedir(dir);
- return NULL;
- }
-
/* Allocate an initial String array */
len = 0;
maxlen = 16;
@@ -339,7 +331,7 @@
if (rv == NULL) goto error;
/* Scan the directory */
- while ((readdir64_r(dir, ptr, &result) == 0) && (result != NULL)) {
+ while ((ptr = readdir64(dir)) != NULL) {
jstring name;
if (!strcmp(ptr->d_name, ".") || !strcmp(ptr->d_name, ".."))
continue;
@@ -360,7 +352,6 @@
(*env)->DeleteLocalRef(env, name);
}
closedir(dir);
- free(ptr);
/* Copy the final results into an appropriately-sized array */
old = rv;
@@ -375,7 +366,6 @@
error:
closedir(dir);
- free(ptr);
return NULL;
}
diff -r e81481fea884 src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
--- a/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
Mon May 07 08:56:35 2018 +0200
+++ b/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
Mon May 07 12:38:42 2018 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2018, 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
@@ -720,24 +720,20 @@
JNIEXPORT jbyteArray JNICALL
Java_sun_nio_fs_UnixNativeDispatcher_readdir(JNIEnv* env, jclass
this, jlong value) {
- struct dirent64* result;
- struct {
- struct dirent64 buf;
- char name_extra[PATH_MAX + 1 - sizeof result->d_name];
- } entry;
- struct dirent64* ptr = &entry.buf;
+ struct dirent64* ptr = NULL;
int res;
DIR* dirp = jlong_to_ptr(value);
/* EINTR not listed as a possible error */
- /* TDB: reentrant version probably not required here */
- res = readdir64_r(dirp, ptr, &result);
+ errno = 0;
+ ptr = readdir64(dirp);
+ res = errno;
#ifdef _AIX
- /* On AIX, readdir_r() returns EBADF (i.e. '9') and sets 'result'
to NULL for the */
+ /* On AIX, readdir() returns EBADF (i.e. '9') and sets 'result'
to NULL for the */
/* directory stream end. Otherwise, 'errno' will contain the error code. */
if (res != 0) {
- res = (result == NULL && res == EBADF) ? 0 : errno;
+ res = (ptr == NULL && res == EBADF) ? 0 : errno;
}
#endif
@@ -745,7 +741,7 @@
throwUnixException(env, res);
return NULL;
} else {
- if (result == NULL) {
+ if (ptr == NULL) {
return NULL;
} else {
jsize len = strlen(ptr->d_name);
diff -r e81481fea884
src/jdk.management/unix/native/libmanagement_ext/OperatingSystemImpl.c
--- a/src/jdk.management/unix/native/libmanagement_ext/OperatingSystemImpl.c
Mon May 07 08:56:35 2018 +0200
+++ b/src/jdk.management/unix/native/libmanagement_ext/OperatingSystemImpl.c
Mon May 07 12:38:42 2018 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2018, 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
@@ -75,17 +75,8 @@
#endif /* _ALLBSD_SOURCE */
static struct dirent* read_dir(DIR* dirp, struct dirent* entry) {
-#ifdef __solaris__
struct dirent* dbuf = readdir(dirp);
return dbuf;
-#else /* __linux__ || _ALLBSD_SOURCE */
- struct dirent* p;
- if (readdir_r(dirp, entry, &p) == 0) {
- return p;
- } else {
- return NULL;
- }
-#endif
}
// true = get available swap in bytes
More information about the hotspot-dev
mailing list