Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions include/my_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -671,12 +671,6 @@ extern char *my_filename(File fd);
extern MY_MODE get_file_perm(ulong perm_flags);
extern bool my_chmod(const char *filename, ulong perm_flags, myf my_flags);

#ifdef EXTRA_DEBUG
void my_print_open_files(void);
#else
#define my_print_open_files()
#endif

extern bool init_tmpdir(MY_TMPDIR *tmpdir, const char *pathlist);
extern char *my_tmpdir(MY_TMPDIR *tmpdir);
extern void free_tmpdir(MY_TMPDIR *tmpdir);
Expand Down
2 changes: 0 additions & 2 deletions mysys/mf_tempfile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ File create_temp_file(char *to, const char *dir, const char *prefix,
}
#endif
if (file >= 0) {
mysql_mutex_lock(&THR_LOCK_open);
my_tmp_file_created++;
mysql_mutex_unlock(&THR_LOCK_open);
}
DBUG_RETURN(file);
}
2 changes: 1 addition & 1 deletion mysys/my_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ uint my_set_max_open_files(uint files) {
void my_free_open_file_info() {
DBUG_ENTER("my_free_file_info");
if (my_file_info != my_file_info_default) {
/* Copy data back for my_print_open_files */
/* Copy data back for my_end */
memcpy((char *)my_file_info_default, my_file_info,
sizeof(*my_file_info_default) * MY_NFILE);
my_free(my_file_info);
Expand Down
22 changes: 9 additions & 13 deletions mysys/my_fopen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,15 @@ FILE *my_fopen(const char *filename, int flags, myf MyFlags) {

int filedesc = my_fileno(fd);
if ((uint)filedesc >= my_file_limit) {
mysql_mutex_lock(&THR_LOCK_open);
my_stream_opened++;
mysql_mutex_unlock(&THR_LOCK_open);
DBUG_RETURN(fd); /* safeguard */
}
dup_filename = my_strdup(key_memory_my_file_info, filename, MyFlags);
if (dup_filename != NULL) {
mysql_mutex_lock(&THR_LOCK_open);
my_file_info[filedesc].name = dup_filename;
my_stream_opened++;
my_file_total_opened++;
my_file_info[filedesc].type = STREAM_BY_FOPEN;
mysql_mutex_unlock(&THR_LOCK_open);
DBUG_PRINT("exit", ("stream: %p", fd));
DBUG_RETURN(fd);
}
Expand Down Expand Up @@ -185,11 +181,16 @@ FILE *my_freopen(const char *path, const char *mode, FILE *stream) {
/* Close a stream */
int my_fclose(FILE *fd, myf MyFlags) {
int err, file;
char *name = NULL;
DBUG_ENTER("my_fclose");
DBUG_PRINT("my", ("stream: %p MyFlags: %d", fd, MyFlags));

mysql_mutex_lock(&THR_LOCK_open);
file = my_fileno(fd);
if ((uint)file < my_file_limit && my_file_info[file].type != UNOPEN) {
name = my_file_info[file].name;
my_file_info[file].type = UNOPEN;
my_file_info[file].name = NULL;
}
#ifndef _WIN32
err = fclose(fd);
#else
Expand All @@ -199,16 +200,13 @@ int my_fclose(FILE *fd, myf MyFlags) {
set_my_errno(errno);
if (MyFlags & (MY_FAE | MY_WME)) {
char errbuf[MYSYS_STRERROR_SIZE];
my_error(EE_BADCLOSE, MYF(0), my_filename(file), my_errno(),
my_error(EE_BADCLOSE, MYF(0), name, my_errno(),
my_strerror(errbuf, sizeof(errbuf), my_errno()));
}
} else
my_stream_opened--;
if ((uint)file < my_file_limit && my_file_info[file].type != UNOPEN) {
my_file_info[file].type = UNOPEN;
my_free(my_file_info[file].name);
}
mysql_mutex_unlock(&THR_LOCK_open);
if (name)
my_free(name);
DBUG_RETURN(err);
} /* my_fclose */

Expand All @@ -235,7 +233,6 @@ FILE *my_fdopen(File Filedes, const char *name, int Flags, myf MyFlags) {
my_strerror(errbuf, sizeof(errbuf), my_errno()));
}
} else {
mysql_mutex_lock(&THR_LOCK_open);
my_stream_opened++;
if ((uint)Filedes < (uint)my_file_limit) {
if (my_file_info[Filedes].type != UNOPEN) {
Expand All @@ -246,7 +243,6 @@ FILE *my_fdopen(File Filedes, const char *name, int Flags, myf MyFlags) {
}
my_file_info[Filedes].type = STREAM_BY_FDOPEN;
}
mysql_mutex_unlock(&THR_LOCK_open);
}

DBUG_PRINT("exit", ("stream: %p", fd));
Expand Down
29 changes: 24 additions & 5 deletions mysys/my_init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,20 +179,39 @@ void my_end(int infoflag) {
operational, so we cannot use DBUG_RETURN.
*/

ulong file_opened = 0, stream_opened = 0;
FILE *info_file = (DBUG_FILE ? DBUG_FILE : stderr);

if (!my_init_done) return;

if ((infoflag & MY_CHECK_ERROR) || (info_file != stderr))

{ /* Test if some file is left open */
if (my_file_opened | my_stream_opened) {
char ebuff[512];
snprintf(ebuff, sizeof(ebuff), EE(EE_OPEN_WARNING), my_file_opened,
my_stream_opened);
uint i;
char ebuff[512];
for (i = 0; i < my_file_limit; i++) {
if (my_file_info[i].type != UNOPEN) {
#ifdef EXTRA_DEBUG
my_message_local(INFORMATION_LEVEL, EE_FILE_NOT_CLOSED,
my_file_info[i].name, i);
#endif
switch (my_file_info[i].type)
{
case STREAM_BY_FOPEN:
case STREAM_BY_FDOPEN:
stream_opened++;
break;
default:
file_opened++;
}
}

}
if (file_opened || stream_opened) {
snprintf(ebuff, sizeof(ebuff), EE(EE_OPEN_WARNING), file_opened,
stream_opened);
my_message_stderr(EE_OPEN_WARNING, ebuff, MYF(0));
DBUG_PRINT("error", ("%s", ebuff));
my_print_open_files();
}
}
my_error_unregister_all();
Expand Down
39 changes: 11 additions & 28 deletions mysys/my_open.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,15 @@ File my_open(const char *FileName, int Flags, myf MyFlags)

int my_close(File fd, myf MyFlags) {
int err;
char *name = NULL;
DBUG_ENTER("my_close");
DBUG_PRINT("my", ("fd: %d MyFlags: %d", fd, MyFlags));

mysql_mutex_lock(&THR_LOCK_open);
if ((uint)fd < my_file_limit && my_file_info[fd].type != UNOPEN) {
name = my_file_info[fd].name;
my_file_info[fd].type = UNOPEN;
my_file_info[fd].name = NULL;
}
#ifndef _WIN32
do {
err = close(fd);
Expand All @@ -110,16 +115,14 @@ int my_close(File fd, myf MyFlags) {
set_my_errno(errno);
if (MyFlags & (MY_FAE | MY_WME)) {
char errbuf[MYSYS_STRERROR_SIZE];
my_error(EE_BADCLOSE, MYF(0), my_filename(fd), my_errno(),
my_error(EE_BADCLOSE, MYF(0), name, my_errno(),
my_strerror(errbuf, sizeof(errbuf), my_errno()));
}
} else
my_file_opened--;
if (name) {
my_free(name);
}
if ((uint)fd < my_file_limit && my_file_info[fd].type != UNOPEN) {
my_free(my_file_info[fd].name);
my_file_info[fd].type = UNOPEN;
}
my_file_opened--;
mysql_mutex_unlock(&THR_LOCK_open);
DBUG_RETURN(err);
} /* my_close */

Expand Down Expand Up @@ -150,20 +153,16 @@ File my_register_filename(File fd, const char *FileName,
#if defined(_WIN32)
set_my_errno(EMFILE);
#else
mysql_mutex_lock(&THR_LOCK_open);
my_file_opened++;
mysql_mutex_unlock(&THR_LOCK_open);
DBUG_RETURN(fd); /* safeguard */
#endif
} else {
dup_filename = my_strdup(key_memory_my_file_info, FileName, MyFlags);
if (dup_filename != NULL) {
mysql_mutex_lock(&THR_LOCK_open);
my_file_info[fd].name = dup_filename;
my_file_opened++;
my_file_total_opened++;
my_file_info[fd].type = type_of_file;
mysql_mutex_unlock(&THR_LOCK_open);
DBUG_PRINT("exit", ("fd: %d", fd));
DBUG_RETURN(fd);
}
Expand All @@ -183,19 +182,3 @@ File my_register_filename(File fd, const char *FileName,
}
DBUG_RETURN(-1);
}

#ifdef EXTRA_DEBUG

void my_print_open_files(void) {
if (my_file_opened | my_stream_opened) {
uint i;
for (i = 0; i < my_file_limit; i++) {
if (my_file_info[i].type != UNOPEN) {
my_message_local(INFORMATION_LEVEL, EE_FILE_NOT_CLOSED,
my_file_info[i].name, i);
}
}
}
}

#endif