Skip to content

Commit 711d458

Browse files
jhauglidprashanttekriwal
authored andcommitted
Bug#25103242: 5.6 DOES NOT BUILD ON FEDORA 25 DUE TO READDIR_R BEING DEPRECATED
Backport from trunk to 5.6 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) (cherry picked from commit 865c124d1bdfd4eeee5eb42ea9faa9c8b45bfbb0) (cherry picked from commit d083887ca7cf90ac370b1a564b5090358f9a097f)
1 parent 105da54 commit 711d458

File tree

5 files changed

+7
-47
lines changed

5 files changed

+7
-47
lines changed

cmake/os/WindowsCache.cmake

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ SET(HAVE_CXX_NEW 1 CACHE INTERNAL "")
4444
SET(HAVE_CXXABI_H CACHE INTERNAL "")
4545
SET(HAVE_DECL_MADVISE CACHE INTERNAL "")
4646
SET(HAVE_DIRECTIO CACHE INTERNAL "")
47-
SET(HAVE_DIRENT_H CACHE INTERNAL "")
4847
SET(HAVE_DLERROR CACHE INTERNAL "")
4948
SET(HAVE_DLFCN_H CACHE INTERNAL "")
5049
SET(HAVE_DLOPEN CACHE INTERNAL "")
@@ -162,7 +161,6 @@ SET(HAVE_PTHREAD_YIELD_ZERO_ARG CACHE INTERNAL "")
162161
SET(HAVE_PUTENV 1 CACHE INTERNAL "")
163162
SET(HAVE_PWD_H CACHE INTERNAL "")
164163
SET(HAVE_RDTSCLL CACHE INTERNAL "")
165-
SET(HAVE_READDIR_R CACHE INTERNAL "")
166164
SET(HAVE_READLINK CACHE INTERNAL "")
167165
SET(HAVE_READ_REAL_TIME CACHE INTERNAL "")
168166
SET(HAVE_REALPATH CACHE INTERNAL "")

config.h.cmake

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#cmakedefine HAVE_CXXABI_H 1
3232
#cmakedefine HAVE_NCURSES_H 1
3333
#cmakedefine HAVE_NDIR_H 1
34-
#cmakedefine HAVE_DIRENT_H 1
3534
#cmakedefine HAVE_DLFCN_H 1
3635
#cmakedefine HAVE_EXECINFO_H 1
3736
#cmakedefine HAVE_FCNTL_H 1
@@ -233,7 +232,6 @@
233232
#cmakedefine HAVE_PUTENV 1
234233
#cmakedefine HAVE_RE_COMP 1
235234
#cmakedefine HAVE_REGCOMP 1
236-
#cmakedefine HAVE_READDIR_R 1
237235
#cmakedefine HAVE_READLINK 1
238236
#cmakedefine HAVE_REALPATH 1
239237
#cmakedefine HAVE_RENAME 1

configure.cmake

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,6 @@ CHECK_INCLUDE_FILES (aio.h HAVE_AIO_H)
347347
CHECK_INCLUDE_FILES (arpa/inet.h HAVE_ARPA_INET_H)
348348
CHECK_INCLUDE_FILES (crypt.h HAVE_CRYPT_H)
349349
CHECK_INCLUDE_FILES (cxxabi.h HAVE_CXXABI_H)
350-
CHECK_INCLUDE_FILES (dirent.h HAVE_DIRENT_H)
351350
CHECK_INCLUDE_FILES (dlfcn.h HAVE_DLFCN_H)
352351
CHECK_INCLUDE_FILES (execinfo.h HAVE_EXECINFO_H)
353352
CHECK_INCLUDE_FILES (fcntl.h HAVE_FCNTL_H)
@@ -568,7 +567,6 @@ CHECK_FUNCTION_EXISTS (pthread_sigmask HAVE_PTHREAD_SIGMASK)
568567
CHECK_FUNCTION_EXISTS (pthread_threadmask HAVE_PTHREAD_THREADMASK)
569568
CHECK_FUNCTION_EXISTS (pthread_yield_np HAVE_PTHREAD_YIELD_NP)
570569
CHECK_FUNCTION_EXISTS (putenv HAVE_PUTENV)
571-
CHECK_FUNCTION_EXISTS (readdir_r HAVE_READDIR_R)
572570
CHECK_FUNCTION_EXISTS (readlink HAVE_READLINK)
573571
CHECK_FUNCTION_EXISTS (re_comp HAVE_RE_COMP)
574572
CHECK_FUNCTION_EXISTS (regcomp HAVE_REGCOMP)

include/my_sys.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,6 @@ extern size_t cleanup_dirname(char * to,const char *from);
713713
extern size_t system_filename(char * to,const char *from);
714714
extern size_t unpack_filename(char * to,const char *from);
715715
extern char * intern_filename(char * to,const char *from);
716-
extern char * directory_file_name(char * dst, const char *src);
717716
extern int pack_filename(char * to, const char *name, size_t max_length);
718717
extern char * my_path(char * to,const char *progname,
719718
const char *own_pathname_part);

mysys/my_lib.c

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,10 @@
2020
#include <m_string.h>
2121
#include <my_dir.h> /* Structs used by my_dir,includes sys/types */
2222
#include "mysys_err.h"
23-
#if defined(HAVE_DIRENT_H)
23+
#if !defined(_WIN32)
2424
# include <dirent.h>
25-
# define NAMLEN(dirent) strlen((dirent)->d_name)
26-
#else
27-
# define dirent direct
28-
# define NAMLEN(dirent) (dirent)->d_namlen
29-
# if defined(HAVE_SYS_NDIR_H)
30-
# include <sys/ndir.h>
31-
# endif
32-
# if defined(HAVE_SYS_DIR_H)
33-
# include <sys/dir.h>
34-
# endif
35-
# if defined(HAVE_NDIR_H)
36-
# include <ndir.h>
3725
# endif
38-
# if defined(_WIN32)
39-
# ifdef __BORLANDC__
40-
# include <dir.h>
41-
# endif
42-
# endif
43-
#endif
4426

45-
#if defined(HAVE_READDIR_R)
46-
#define READDIR(A,B,C) ((errno=readdir_r(A,B,&C)) != 0 || !C)
47-
#else
48-
#define READDIR(A,B,C) (!(C=readdir(A)))
49-
#endif
5027

5128
/*
5229
We are assuming that directory we are reading is either has less than
@@ -88,6 +65,8 @@ static int comp_names(struct fileinfo *a, struct fileinfo *b)
8865

8966
#if !defined(_WIN32)
9067

68+
static char* directory_file_name(char *dst, const char *src);
69+
9170
MY_DIR *my_dir(const char *path, myf MyFlags)
9271
{
9372
char *buffer;
@@ -96,17 +75,12 @@ MY_DIR *my_dir(const char *path, myf MyFlags)
9675
DYNAMIC_ARRAY *dir_entries_storage;
9776
MEM_ROOT *names_storage;
9877
DIR *dirp;
99-
struct dirent *dp;
10078
char tmp_path[FN_REFLEN + 2], *tmp_file;
101-
char dirent_tmp[sizeof(struct dirent)+_POSIX_PATH_MAX+1];
79+
const struct dirent *dp;
10280

10381
DBUG_ENTER("my_dir");
10482
DBUG_PRINT("my",("path: '%s' MyFlags: %d",path,MyFlags));
10583

106-
#if !defined(HAVE_READDIR_R)
107-
mysql_mutex_lock(&THR_LOCK_open);
108-
#endif
109-
11084
dirp = opendir(directory_file_name(tmp_path,(char *) path));
11185
#if defined(__amiga__)
11286
if ((dirp->dd_fd) < 0) /* Directory doesn't exists */
@@ -135,9 +109,7 @@ MY_DIR *my_dir(const char *path, myf MyFlags)
135109

136110
tmp_file=strend(tmp_path);
137111

138-
dp= (struct dirent*) dirent_tmp;
139-
140-
while (!(READDIR(dirp,(struct dirent*) dirent_tmp,dp)))
112+
for (dp= readdir(dirp) ; dp; dp= readdir(dirp))
141113
{
142114
if (!(finfo.name= strdup_root(names_storage, dp->d_name)))
143115
goto error;
@@ -162,9 +134,7 @@ MY_DIR *my_dir(const char *path, myf MyFlags)
162134
}
163135

164136
(void) closedir(dirp);
165-
#if !defined(HAVE_READDIR_R)
166-
mysql_mutex_unlock(&THR_LOCK_open);
167-
#endif
137+
168138
result->dir_entry= (FILEINFO *)dir_entries_storage->buffer;
169139
result->number_off_files= dir_entries_storage->elements;
170140

@@ -174,9 +144,6 @@ MY_DIR *my_dir(const char *path, myf MyFlags)
174144
DBUG_RETURN(result);
175145

176146
error:
177-
#if !defined(HAVE_READDIR_R)
178-
mysql_mutex_unlock(&THR_LOCK_open);
179-
#endif
180147
my_errno=errno;
181148
if (dirp)
182149
(void) closedir(dirp);
@@ -198,7 +165,7 @@ MY_DIR *my_dir(const char *path, myf MyFlags)
198165
* Returns pointer to dst;
199166
*/
200167

201-
char * directory_file_name (char * dst, const char *src)
168+
static char* directory_file_name(char *dst, const char *src)
202169
{
203170
/* Process as Unix format: just remove test the final slash. */
204171
char *end;

0 commit comments

Comments
 (0)