Blob Blame History Raw
MySQL port of the following MariaDB patch:

commit 8e781601f46938cb4228bd9a966a9d6871c06859
Author: Sergei Golubchik <serg@mariadb.org>
Date:   Fri Apr 24 21:41:00 2015 +0200

    MDEV-6870 Not possible to use FIFO file as a general_log file
    
    Remove the too restrictive bugfix for bug#67088.
    FIFO can be used for general/slow logs, but lseek() and fsync() on
    FIFO fail. And open() needs to be non-blocking, in case the other
    end isn't reading.

RHBZ: #1219496

diff -rup mysql-5.6.33.orig/mysql-test/r/log_errchk.result mysql-5.6.33/mysql-test/r/log_errchk.result
--- mysql-5.6.33.orig/mysql-test/r/log_errchk.result	2016-08-26 13:22:35.000000000 +0200
+++ mysql-5.6.33/mysql-test/r/log_errchk.result	2016-10-06 16:13:15.102478779 +0200
@@ -1,5 +1,4 @@
-call mtr.add_suppression("Could not open");
-# Case 1: Setting fife file to general_log_file and slow_query_log_file
+# Case 1: Setting fifo file to general_log_file and slow_query_log_file
 #         system variable.
 SET GLOBAL general_log_file="MYSQLTEST_VARDIR/tmp/general_log.fifo";;
 ERROR 42000: Variable 'general_log_file' can't be set to the value of 'MYSQLTEST_VARDIR/tmp/general_log.fifo'
@@ -7,4 +6,6 @@ SET GLOBAL slow_query_log_file="MYSQLTES
 ERROR 42000: Variable 'slow_query_log_file' can't be set to the value of 'MYSQLTEST_VARDIR/tmp/slow_log.fifo'
 # Case 2: Starting server with fifo file as general log file
 #         and slow query log file.
+call mtr.add_suppression("Could not open .* for logging \\(error 6\\)");
+call mtr.add_suppression("File '.*' not found \\(Errcode: 6\\)");
 Setting fifo file as general log file and slow query log failed.
diff -rup mysql-5.6.33.orig/mysql-test/t/log_errchk.test mysql-5.6.33/mysql-test/t/log_errchk.test
--- mysql-5.6.33.orig/mysql-test/t/log_errchk.test	2016-08-26 13:22:35.000000000 +0200
+++ mysql-5.6.33/mysql-test/t/log_errchk.test	2016-10-06 16:16:23.130667809 +0200
@@ -7,8 +7,8 @@
 # Bug#14757009 : WHEN THE GENERAL_LOG IS A SOCKET AND THE READER GOES AWAY,
 #                MYSQL QUITS WORKING.
 #
-call mtr.add_suppression("Could not open");
-
+# MariaDB: MDEV-6870 Not possible to use FIFO file as a general_log file
+#
 --let $gen_log_file= $MYSQLTEST_VARDIR/tmp/general_log.fifo
 --let $slow_query_log_file= $MYSQLTEST_VARDIR/tmp/slow_log.fifo
 --let GREP_FILE=$MYSQLTEST_VARDIR/log/mysqld.1.err
@@ -16,10 +16,9 @@ call mtr.add_suppression("Could not open
 --exec mkfifo $gen_log_file
 --exec mkfifo $slow_query_log_file
 
---echo # Case 1: Setting fife file to general_log_file and slow_query_log_file
+--echo # Case 1: Setting fifo file to general_log_file and slow_query_log_file
 --echo #         system variable.
-# Only regular files can be set to general log. Setting fifo file to general log
-# reports an error.
+# Setting fifo file to general log reports an error because the other end is closed
 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
 --error ER_WRONG_VALUE_FOR_VAR
 --eval SET GLOBAL general_log_file="$gen_log_file";
@@ -39,11 +38,12 @@ call mtr.add_suppression("Could not open
 --exec echo "restart: --general-log-file=$gen_log_file --slow-query-log-file=$slow_query_log_file" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
 --source include/wait_until_connected_again.inc
 
-# With fix error should be reported in the error log file if file is not a
-# regular file.
+# Error 6 is reported, because the other end is closed
+call mtr.add_suppression("Could not open .* for logging \\(error 6\\)");
+call mtr.add_suppression("File '.*' not found \\(Errcode: 6\\)");
 --perl
   my $file= $ENV{'GREP_FILE'};
-  my $pattern= "Turning logging off for the whole duration";
+  my $pattern= "for logging \\(error 6\\)\\. Turning logging off for the whole duration";
   open(FILE, "$file") or die("Unable to open $file: $!\n");
   my $count = 0;
   while (<FILE>) {
diff -rup mysql-5.6.33.orig/sql/log.cc mysql-5.6.33/sql/log.cc
--- mysql-5.6.33.orig/sql/log.cc	2016-08-26 13:22:35.000000000 +0200
+++ mysql-5.6.33/sql/log.cc	2016-10-06 16:44:57.683152679 +0200
@@ -1598,6 +1598,7 @@ bool MYSQL_LOG::open(
   MY_STAT f_stat;
   File file= -1;
   my_off_t pos= 0;
+  bool is_fifo = false;
   int open_flags= O_CREAT | O_BINARY;
   DBUG_ENTER("MYSQL_LOG::open");
   DBUG_PRINT("enter", ("log_type: %d", (int) log_type_arg));
@@ -1615,15 +1616,17 @@ bool MYSQL_LOG::open(
       DBUG_EVALUATE_IF("fault_injection_init_name", log_type == LOG_BIN, 0))
     goto err;
 
-  /* File is regular writable file */
-  if (my_stat(log_file_name, &f_stat, MYF(0)) && !MY_S_ISREG(f_stat.st_mode))
-    goto err;
+  is_fifo = my_stat(log_file_name, &f_stat, MYF(0)) &&
+            MY_S_ISFIFO(f_stat.st_mode);
 
   if (io_cache_type == SEQ_READ_APPEND)
     open_flags |= O_RDWR | O_APPEND;
   else
     open_flags |= O_WRONLY | (log_type == LOG_BIN ? 0 : O_APPEND);
 
+  if (is_fifo)
+    open_flags |= O_NONBLOCK;
+
   db[0]= 0;
 
 #ifdef HAVE_PSI_INTERFACE
@@ -1648,7 +1651,9 @@ bool MYSQL_LOG::open(
     goto err;
 #endif // _WIN32
 
-  if ((pos= mysql_file_tell(file, MYF(MY_WME))) == MY_FILEPOS_ERROR)
+  if (is_fifo)
+    pos= 0;
+  else if ((pos= mysql_file_tell(file, MYF(MY_WME))) == MY_FILEPOS_ERROR)
   {
     if (my_errno == ESPIPE)
       pos= 0;
@@ -1756,7 +1761,7 @@ void MYSQL_LOG::close(uint exiting)
   {
     end_io_cache(&log_file);
 
-    if (mysql_file_sync(log_file.file, MYF(MY_WME)) && ! write_error)
+    if (log_type == LOG_BIN && mysql_file_sync(log_file.file, MYF(MY_WME)) && ! write_error)
     {
       char errbuf[MYSYS_STRERROR_SIZE];
       write_error= 1;