Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
d4ffbd3e
Commit
d4ffbd3e
authored
Jan 07, 2011
by
Davi Arnaut
Browse files
Options
Browse Files
Download
Plain Diff
Merge of mysql-5.1 into mysql-5.5.
parents
b342d3e7
844d6ed4
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
144 additions
and
65 deletions
+144
-65
include/my_sys.h
include/my_sys.h
+1
-0
mysys/my_fopen.c
mysys/my_fopen.c
+133
-1
sql/log.cc
sql/log.cc
+10
-64
No files found.
include/my_sys.h
View file @
d4ffbd3e
...
@@ -631,6 +631,7 @@ extern const char** get_global_errmsgs();
...
@@ -631,6 +631,7 @@ extern const char** get_global_errmsgs();
extern
void
wait_for_free_space
(
const
char
*
filename
,
int
errors
);
extern
void
wait_for_free_space
(
const
char
*
filename
,
int
errors
);
extern
FILE
*
my_fopen
(
const
char
*
FileName
,
int
Flags
,
myf
MyFlags
);
extern
FILE
*
my_fopen
(
const
char
*
FileName
,
int
Flags
,
myf
MyFlags
);
extern
FILE
*
my_fdopen
(
File
Filedes
,
const
char
*
name
,
int
Flags
,
myf
MyFlags
);
extern
FILE
*
my_fdopen
(
File
Filedes
,
const
char
*
name
,
int
Flags
,
myf
MyFlags
);
extern
FILE
*
my_freopen
(
const
char
*
path
,
const
char
*
mode
,
FILE
*
stream
);
extern
int
my_fclose
(
FILE
*
fd
,
myf
MyFlags
);
extern
int
my_fclose
(
FILE
*
fd
,
myf
MyFlags
);
extern
File
my_fileno
(
FILE
*
fd
);
extern
File
my_fileno
(
FILE
*
fd
);
extern
int
my_chsize
(
File
fd
,
my_off_t
newlength
,
int
filler
,
myf
MyFlags
);
extern
int
my_chsize
(
File
fd
,
my_off_t
newlength
,
int
filler
,
myf
MyFlags
);
...
...
mysys/my_fopen.c
View file @
d4ffbd3e
...
@@ -18,6 +18,10 @@
...
@@ -18,6 +18,10 @@
#include <errno.h>
#include <errno.h>
#include "mysys_err.h"
#include "mysys_err.h"
#if defined(__FreeBSD__)
extern
int
getosreldate
(
void
);
#endif
static
void
make_ftype
(
char
*
to
,
int
flag
);
static
void
make_ftype
(
char
*
to
,
int
flag
);
/*
/*
...
@@ -89,7 +93,135 @@ FILE *my_fopen(const char *filename, int flags, myf MyFlags)
...
@@ -89,7 +93,135 @@ FILE *my_fopen(const char *filename, int flags, myf MyFlags)
}
/* my_fopen */
}
/* my_fopen */
/* Close a stream */
#if defined(_WIN32)
static
FILE
*
my_win_freopen
(
const
char
*
path
,
const
char
*
mode
,
FILE
*
stream
)
{
int
handle_fd
,
fd
=
_fileno
(
stream
);
HANDLE
osfh
;
DBUG_ASSERT
(
path
&&
stream
);
/* Services don't have stdout/stderr on Windows, so _fileno returns -1. */
if
(
fd
<
0
)
{
if
(
!
freopen
(
path
,
mode
,
stream
))
return
NULL
;
fd
=
_fileno
(
stream
);
}
if
((
osfh
=
CreateFile
(
path
,
GENERIC_READ
|
GENERIC_WRITE
,
FILE_SHARE_READ
|
FILE_SHARE_WRITE
|
FILE_SHARE_DELETE
,
NULL
,
OPEN_ALWAYS
,
FILE_ATTRIBUTE_NORMAL
,
NULL
))
==
INVALID_HANDLE_VALUE
)
return
NULL
;
if
((
handle_fd
=
_open_osfhandle
((
intptr_t
)
osfh
,
_O_APPEND
|
_O_TEXT
))
==
-
1
)
{
CloseHandle
(
osfh
);
return
NULL
;
}
if
(
_dup2
(
handle_fd
,
fd
)
<
0
)
{
CloseHandle
(
osfh
);
return
NULL
;
}
_close
(
handle_fd
);
return
stream
;
}
#elif defined(__FreeBSD__)
/* No close operation hook. */
static
int
no_close
(
void
*
cookie
__attribute__
((
unused
)))
{
return
0
;
}
/*
A hack around a race condition in the implementation of freopen.
The race condition steams from the fact that the current fd of
the stream is closed before its number is used to duplicate the
new file descriptor. This defeats the desired atomicity of the
close and duplicate of dup2().
See PR number 79887 for reference:
http://www.freebsd.org/cgi/query-pr.cgi?pr=79887
*/
static
FILE
*
my_freebsd_freopen
(
const
char
*
path
,
const
char
*
mode
,
FILE
*
stream
)
{
int
old_fd
;
FILE
*
result
;
flockfile
(
stream
);
old_fd
=
fileno
(
stream
);
/* Use a no operation close hook to avoid having the fd closed. */
stream
->
_close
=
no_close
;
/* Relies on the implicit dup2 to close old_fd. */
result
=
freopen
(
path
,
mode
,
stream
);
/* If successful, the _close hook was replaced. */
if
(
result
==
NULL
)
close
(
old_fd
);
else
funlockfile
(
result
);
return
result
;
}
#endif
/**
Change the file associated with a file stream.
@param path Path to file.
@param mode Mode of the stream.
@param stream File stream.
@note
This function is used to redirect stdout and stderr to a file and
subsequently to close and reopen that file for log rotation.
@retval A FILE pointer on success. Otherwise, NULL.
*/
FILE
*
my_freopen
(
const
char
*
path
,
const
char
*
mode
,
FILE
*
stream
)
{
FILE
*
result
;
#if defined(_WIN32)
result
=
my_win_freopen
(
path
,
mode
,
stream
);
#elif defined(__FreeBSD__)
/*
XXX: Once the fix is ported to the stable releases, this should
be dependent upon the specific FreeBSD versions. Check at:
http://www.freebsd.org/cgi/query-pr.cgi?pr=79887
*/
if
(
getosreldate
()
>
900027
)
result
=
freopen
(
path
,
mode
,
stream
);
else
result
=
my_freebsd_freopen
(
path
,
mode
,
stream
);
#else
result
=
freopen
(
path
,
mode
,
stream
);
#endif
return
result
;
}
/* Close a stream */
/* Close a stream */
int
my_fclose
(
FILE
*
fd
,
myf
MyFlags
)
int
my_fclose
(
FILE
*
fd
,
myf
MyFlags
)
...
...
sql/log.cc
View file @
d4ffbd3e
...
@@ -5686,80 +5686,26 @@ void sql_perror(const char *message)
...
@@ -5686,80 +5686,26 @@ void sql_perror(const char *message)
}
}
#ifdef __WIN__
/*
Change the file associated with two output streams. Used to
redirect stdout and stderr to a file. The streams are reopened
only for appending (writing at end of file).
*/
extern
"C"
my_bool
reopen_fstreams
(
const
char
*
filename
,
extern
"C"
my_bool
reopen_fstreams
(
const
char
*
filename
,
FILE
*
outstream
,
FILE
*
errstream
)
FILE
*
outstream
,
FILE
*
errstream
)
{
{
int
handle_fd
;
if
(
outstream
&&
!
my_freopen
(
filename
,
"a"
,
outstream
))
int
err_fd
,
out_fd
;
HANDLE
osfh
;
DBUG_ASSERT
(
filename
&&
errstream
);
// Services don't have stdout/stderr on Windows, so _fileno returns -1.
err_fd
=
_fileno
(
errstream
);
if
(
err_fd
<
0
)
{
if
(
!
freopen
(
filename
,
"a+"
,
errstream
))
return
TRUE
;
return
TRUE
;
setbuf
(
errstream
,
NULL
);
if
(
errstream
&&
!
my_freopen
(
filename
,
"a"
,
errstream
))
err_fd
=
_fileno
(
errstream
);
}
if
(
outstream
)
{
out_fd
=
_fileno
(
outstream
);
if
(
out_fd
<
0
)
{
if
(
!
freopen
(
filename
,
"a+"
,
outstream
))
return
TRUE
;
return
TRUE
;
out_fd
=
_fileno
(
outstream
);
}
}
if
((
osfh
=
CreateFile
(
filename
,
GENERIC_READ
|
GENERIC_WRITE
,
/* The error stream must be unbuffered. */
FILE_SHARE_READ
|
FILE_SHARE_WRITE
|
if
(
errstream
)
FILE_SHARE_DELETE
,
NULL
,
setbuf
(
errstream
,
NULL
);
OPEN_ALWAYS
,
FILE_ATTRIBUTE_NORMAL
,
NULL
))
==
INVALID_HANDLE_VALUE
)
return
TRUE
;
if
((
handle_fd
=
_open_osfhandle
((
intptr_t
)
osfh
,
_O_APPEND
|
_O_TEXT
))
==
-
1
)
{
CloseHandle
(
osfh
);
return
TRUE
;
}
if
(
_dup2
(
handle_fd
,
err_fd
)
<
0
)
{
CloseHandle
(
osfh
);
return
TRUE
;
}
if
(
outstream
&&
_dup2
(
handle_fd
,
out_fd
)
<
0
)
{
CloseHandle
(
osfh
);
return
TRUE
;
}
_close
(
handle_fd
);
return
FALSE
;
}
#else
extern
"C"
my_bool
reopen_fstreams
(
const
char
*
filename
,
FILE
*
outstream
,
FILE
*
errstream
)
{
if
(
outstream
&&
!
freopen
(
filename
,
"a+"
,
outstream
))
return
TRUE
;
if
(
errstream
&&
!
freopen
(
filename
,
"a+"
,
errstream
))
return
TRUE
;
return
FALSE
;
return
FALSE
;
}
}
#endif
/*
/*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment