Skip to content

Commit c93cf20

Browse files
committed
Bug#24437737: MYSQL 5.7.1{3,4} DOES NOT COMPILE OB GCC 6.1.1
Backport from trunk to 5.7 of: Bug#23708395: GLIBC 2.24 DEPRECATES READDIR_R() BREAKING DEBUG BUILD OF MYSQL SERVER As of glibc 2.24, readdir_r() has been deprecated. This breaks our debug builds since the deprecation warning is upgraded to an error during compilation. This patch fixes the problem by removing use of readdir_r() and using readdir() instead. This is thread safe as long as readdir() is only used concurrently on different DIR* - which it is in our case. POSIX quote: "The pointer returned by readdir() points to data which may be overwritten by another call to readdir() on the same directory stream. This data is not overwritten by another call to readdir() on a different directory stream." Change-Id: I85a6f5da2d48c8d5a9804cd6281411d9e757f46c (cherry picked from commit ba5245e9fef2257d60213076598268f544ca7109)
1 parent e68b394 commit c93cf20

File tree

5 files changed

+15
-41
lines changed

5 files changed

+15
-41
lines changed

cmake/os/WindowsCache.cmake

-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ SET(CMAKE_HAVE_PTHREAD_H CACHE INTERNAL "") # Only needed by CMake
3636
# Header files
3737
SET(HAVE_ALLOCA_H CACHE INTERNAL "")
3838
SET(HAVE_ARPA_INET_H CACHE INTERNAL "")
39-
SET(HAVE_DIRENT_H CACHE INTERNAL "")
4039
SET(HAVE_DLFCN_H CACHE INTERNAL "")
4140
SET(HAVE_EXECINFO_H CACHE INTERNAL "")
4241
SET(HAVE_FPU_CONTROL_H CACHE INTERNAL "")
@@ -118,7 +117,6 @@ SET(HAVE_POSIX_MEMALIGN CACHE INTERNAL "")
118117
SET(HAVE_PREAD CACHE INTERNAL "")
119118
SET(HAVE_PTHREAD_CONDATTR_SETCLOCK CACHE INTERNAL "")
120119
SET(HAVE_PTHREAD_SIGMASK CACHE INTERNAL "")
121-
SET(HAVE_READDIR_R CACHE INTERNAL "")
122120
SET(HAVE_READLINK CACHE INTERNAL "")
123121
SET(HAVE_REALPATH CACHE INTERNAL "")
124122
SET(HAVE_SETFD CACHE INTERNAL "")

config.h.cmake

-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
/* Header files */
3535
#cmakedefine HAVE_ALLOCA_H 1
3636
#cmakedefine HAVE_ARPA_INET_H 1
37-
#cmakedefine HAVE_DIRENT_H 1
3837
#cmakedefine HAVE_DLFCN_H 1
3938
#cmakedefine HAVE_EXECINFO_H 1
4039
#cmakedefine HAVE_FPU_CONTROL_H 1
@@ -116,7 +115,6 @@
116115
#cmakedefine HAVE_PREAD 1
117116
#cmakedefine HAVE_PTHREAD_CONDATTR_SETCLOCK 1
118117
#cmakedefine HAVE_PTHREAD_SIGMASK 1
119-
#cmakedefine HAVE_READDIR_R 1
120118
#cmakedefine HAVE_READLINK 1
121119
#cmakedefine HAVE_REALPATH 1
122120
#cmakedefine HAVE_SETFD 1

configure.cmake

-2
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,6 @@ INCLUDE (CheckIncludeFiles)
395395

396396
CHECK_INCLUDE_FILES (alloca.h HAVE_ALLOCA_H)
397397
CHECK_INCLUDE_FILES (arpa/inet.h HAVE_ARPA_INET_H)
398-
CHECK_INCLUDE_FILES (dirent.h HAVE_DIRENT_H)
399398
CHECK_INCLUDE_FILES (dlfcn.h HAVE_DLFCN_H)
400399
CHECK_INCLUDE_FILES (execinfo.h HAVE_EXECINFO_H)
401400
CHECK_INCLUDE_FILES (fpu_control.h HAVE_FPU_CONTROL_H)
@@ -482,7 +481,6 @@ CHECK_FUNCTION_EXISTS (posix_memalign HAVE_POSIX_MEMALIGN)
482481
CHECK_FUNCTION_EXISTS (pread HAVE_PREAD) # Used by NDB
483482
CHECK_FUNCTION_EXISTS (pthread_condattr_setclock HAVE_PTHREAD_CONDATTR_SETCLOCK)
484483
CHECK_FUNCTION_EXISTS (pthread_sigmask HAVE_PTHREAD_SIGMASK)
485-
CHECK_FUNCTION_EXISTS (readdir_r HAVE_READDIR_R)
486484
CHECK_FUNCTION_EXISTS (readlink HAVE_READLINK)
487485
CHECK_FUNCTION_EXISTS (realpath HAVE_REALPATH)
488486
CHECK_FUNCTION_EXISTS (setfd HAVE_SETFD)

include/my_sys.h

-1
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,6 @@ extern size_t cleanup_dirname(char * to,const char *from);
681681
extern size_t system_filename(char * to,const char *from);
682682
extern size_t unpack_filename(char * to,const char *from);
683683
extern char * intern_filename(char * to,const char *from);
684-
extern char * directory_file_name(char * dst, const char *src);
685684
extern int pack_filename(char * to, const char *name, size_t max_length);
686685
extern char * my_path(char * to,const char *progname,
687686
const char *own_pathname_part);

mysys/my_lib.c

+15-34
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,10 @@
2222
#include "my_dir.h" /* Structs used by my_dir,includes sys/types */
2323
#include "mysys_err.h"
2424
#include "my_thread_local.h"
25-
#if defined(HAVE_DIRENT_H)
25+
#if !defined(_WIN32)
2626
# include <dirent.h>
27-
# define NAMLEN(dirent) strlen((dirent)->d_name)
28-
#else
29-
# define dirent direct
30-
# define NAMLEN(dirent) (dirent)->d_namlen
3127
#endif
3228

33-
#if defined(HAVE_READDIR_R)
34-
#define READDIR(A,B,C) ((errno=readdir_r(A,B,&C)) != 0 || !C)
35-
#else
36-
#define READDIR(A,B,C) (!(C=readdir(A)))
37-
#endif
3829

3930
/*
4031
We are assuming that directory we are reading is either has less than
@@ -75,6 +66,8 @@ static int comp_names(struct fileinfo *a, struct fileinfo *b)
7566

7667
#if !defined(_WIN32)
7768

69+
static char* directory_file_name(char *dst, const char *src);
70+
7871
MY_DIR *my_dir(const char *path, myf MyFlags)
7972
{
8073
char *buffer;
@@ -83,29 +76,24 @@ MY_DIR *my_dir(const char *path, myf MyFlags)
8376
DYNAMIC_ARRAY *dir_entries_storage;
8477
MEM_ROOT *names_storage;
8578
DIR *dirp;
86-
struct dirent *dp;
8779
char tmp_path[FN_REFLEN + 2], *tmp_file;
88-
char dirent_tmp[sizeof(struct dirent)+_POSIX_PATH_MAX+1];
80+
const struct dirent *dp;
8981

9082
DBUG_ENTER("my_dir");
9183
DBUG_PRINT("my",("path: '%s' MyFlags: %d",path,MyFlags));
9284

93-
#if !defined(HAVE_READDIR_R)
94-
mysql_mutex_lock(&THR_LOCK_open);
95-
#endif
96-
9785
dirp = opendir(directory_file_name(tmp_path,(char *) path));
98-
if (dirp == NULL ||
86+
if (dirp == NULL ||
9987
! (buffer= my_malloc(key_memory_MY_DIR,
10088
ALIGN_SIZE(sizeof(MY_DIR)) +
10189
ALIGN_SIZE(sizeof(DYNAMIC_ARRAY)) +
10290
sizeof(MEM_ROOT), MyFlags)))
10391
goto error;
10492

105-
dir_entries_storage= (DYNAMIC_ARRAY*)(buffer + ALIGN_SIZE(sizeof(MY_DIR)));
93+
dir_entries_storage= (DYNAMIC_ARRAY*)(buffer + ALIGN_SIZE(sizeof(MY_DIR)));
10694
names_storage= (MEM_ROOT*)(buffer + ALIGN_SIZE(sizeof(MY_DIR)) +
10795
ALIGN_SIZE(sizeof(DYNAMIC_ARRAY)));
108-
96+
10997
if (my_init_dynamic_array(dir_entries_storage,
11098
key_memory_MY_DIR,
11199
sizeof(FILEINFO),
@@ -116,25 +104,23 @@ MY_DIR *my_dir(const char *path, myf MyFlags)
116104
goto error;
117105
}
118106
init_alloc_root(key_memory_MY_DIR, names_storage, NAMES_START_SIZE, NAMES_START_SIZE);
119-
107+
120108
/* MY_DIR structure is allocated and completly initialized at this point */
121109
result= (MY_DIR*)buffer;
122110

123111
tmp_file=strend(tmp_path);
124112

125-
dp= (struct dirent*) dirent_tmp;
126-
127-
while (!(READDIR(dirp,(struct dirent*) dirent_tmp,dp)))
113+
for (dp= readdir(dirp) ; dp; dp= readdir(dirp))
128114
{
129115
if (!(finfo.name= strdup_root(names_storage, dp->d_name)))
130116
goto error;
131-
117+
132118
if (MyFlags & MY_WANT_STAT)
133119
{
134-
if (!(finfo.mystat= (MY_STAT*)alloc_root(names_storage,
120+
if (!(finfo.mystat= (MY_STAT*)alloc_root(names_storage,
135121
sizeof(MY_STAT))))
136122
goto error;
137-
123+
138124
memset(finfo.mystat, 0, sizeof(MY_STAT));
139125
(void) my_stpcpy(tmp_file,dp->d_name);
140126
(void) my_stat(tmp_path, finfo.mystat, MyFlags);
@@ -149,21 +135,16 @@ MY_DIR *my_dir(const char *path, myf MyFlags)
149135
}
150136

151137
(void) closedir(dirp);
152-
#if !defined(HAVE_READDIR_R)
153-
mysql_mutex_unlock(&THR_LOCK_open);
154-
#endif
138+
155139
result->dir_entry= (FILEINFO *)dir_entries_storage->buffer;
156140
result->number_off_files= dir_entries_storage->elements;
157-
141+
158142
if (!(MyFlags & MY_DONT_SORT))
159143
my_qsort((void *) result->dir_entry, result->number_off_files,
160144
sizeof(FILEINFO), (qsort_cmp) comp_names);
161145
DBUG_RETURN(result);
162146

163147
error:
164-
#if !defined(HAVE_READDIR_R)
165-
mysql_mutex_unlock(&THR_LOCK_open);
166-
#endif
167148
set_my_errno(errno);
168149
if (dirp)
169150
(void) closedir(dirp);
@@ -185,7 +166,7 @@ MY_DIR *my_dir(const char *path, myf MyFlags)
185166
* Returns pointer to dst;
186167
*/
187168

188-
char * directory_file_name (char * dst, const char *src)
169+
static char* directory_file_name(char *dst, const char *src)
189170
{
190171
/* Process as Unix format: just remove test the final slash. */
191172
char *end;

0 commit comments

Comments
 (0)