summaryrefslogtreecommitdiff
path: root/plugin/server_audit
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2017-10-04 08:24:06 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2017-10-04 08:24:06 +0300
commit2c1067166d7e8a9541578220b408f1e553e23916 (patch)
tree2ba0932f92d88e01d51393de63dda842f6daf320 /plugin/server_audit
parent2cf3e2ea2fca3d3613309de94d55c88dedb3831a (diff)
parent61b2618d3aae78950f1b8dbe8d4482573c77875d (diff)
downloadmariadb-git-2c1067166d7e8a9541578220b408f1e553e23916.tar.gz
Merge bb-10.2-ext into 10.3
Diffstat (limited to 'plugin/server_audit')
-rw-r--r--plugin/server_audit/server_audit.c61
1 files changed, 29 insertions, 32 deletions
diff --git a/plugin/server_audit/server_audit.c b/plugin/server_audit/server_audit.c
index 2f6c8a8afda..1035065eec0 100644
--- a/plugin/server_audit/server_audit.c
+++ b/plugin/server_audit/server_audit.c
@@ -20,6 +20,7 @@
#define _my_thread_var loc_thread_var
#include <my_config.h>
+#include <assert.h>
#ifndef _WIN32
#include <syslog.h>
@@ -138,7 +139,7 @@ static size_t loc_write(File Filedes, const uchar *Buffer, size_t Count)
{
size_t writtenbytes;
#ifdef _WIN32
- writtenbytes= my_win_write(Filedes, Buffer, Count);
+ writtenbytes= (size_t)_write(Filedes, Buffer, (unsigned int)Count);
#else
writtenbytes= write(Filedes, Buffer, Count);
#endif
@@ -152,10 +153,29 @@ static File loc_open(const char *FileName, int Flags)
/* Special flags */
{
File fd;
-#if defined(_WIN32)
- fd= my_win_open(FileName, Flags);
+#ifdef _WIN32
+ HANDLE h;
+ /*
+ We could just use _open() here. but prefer to open in unix-similar way
+ just like my_open() does it on Windows.
+ This gives atomic multiprocess-safe appends, and possibility to rename
+ or even delete file while it is open, and CRT lacks this features.
+ */
+ assert(Flags == (O_APPEND | O_CREAT | O_WRONLY));
+ h= CreateFile(FileName, FILE_APPEND_DATA,
+ FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, NULL,
+ OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+ if (h == INVALID_HANDLE_VALUE)
+ {
+ fd= -1;
+ my_osmaperr(GetLastError());
+ }
+ else
+ {
+ fd= _open_osfhandle((intptr)h, O_WRONLY|O_BINARY);
+ }
#else
- fd = open(FileName, Flags, my_umask);
+ fd= open(FileName, Flags, my_umask);
#endif
my_errno= errno;
return fd;
@@ -171,7 +191,7 @@ static int loc_close(File fd)
err= close(fd);
} while (err == -1 && errno == EINTR);
#else
- err= my_win_close(fd);
+ err= close(fd);
#endif
my_errno=errno;
return err;
@@ -201,32 +221,9 @@ static int loc_rename(const char *from, const char *to)
}
-static my_off_t loc_seek(File fd, my_off_t pos, int whence)
-{
- os_off_t newpos= -1;
-#ifdef _WIN32
- newpos= my_win_lseek(fd, pos, whence);
-#else
- newpos= lseek(fd, pos, whence);
-#endif
- if (newpos == (os_off_t) -1)
- {
- my_errno= errno;
- return MY_FILEPOS_ERROR;
- }
-
- return (my_off_t) newpos;
-}
-
-
static my_off_t loc_tell(File fd)
{
- os_off_t pos;
-#if defined (HAVE_TELL) && !defined (_WIN32)
- pos= tell(fd);
-#else
- pos= loc_seek(fd, 0L, MY_SEEK_CUR);
-#endif
+ os_off_t pos= IF_WIN(_telli64(fd),lseek(fd, 0, SEEK_CUR));
if (pos == (os_off_t) -1)
{
my_errno= errno;
@@ -990,7 +987,7 @@ static int start_logging()
if (output_type == OUTPUT_FILE)
{
char alt_path_buffer[FN_REFLEN+1+DEFAULT_FILENAME_LEN];
- MY_STAT *f_stat;
+ struct stat *f_stat= (struct stat *)alt_path_buffer;
const char *alt_fname= file_path;
while (*alt_fname == ' ')
@@ -1005,7 +1002,7 @@ static int start_logging()
{
/* See if the directory exists with the name of file_path. */
/* Log file name should be [file_path]/server_audit.log then. */
- if ((f_stat= my_stat(file_path, (MY_STAT *)alt_path_buffer, MYF(0))) &&
+ if (stat(file_path, (struct stat *)alt_path_buffer) == 0 &&
S_ISDIR(f_stat->st_mode))
{
size_t p_len= strlen(file_path);
@@ -1421,7 +1418,7 @@ static size_t escape_string_hide_passwords(const char *str, unsigned int len,
}
next_s++;
}
- len-= next_s - str;
+ len-= (uint)(next_s - str);
str= next_s;
continue;
}