Bug #59847 Error closing the general/query logfile, if file is a named pipe/socket/fifo
Submitted: 31 Jan 2011 14:32 Modified: 25 Mar 2011 1:41
Reporter: Gustav Mogensen Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Logging Severity:S3 (Non-critical)
Version:5.1.49-enterprise-gpl-pro-log OS:Linux (2.6.18-238.1.1.el5)
Assigned to: CPU Architecture:Any

[31 Jan 2011 14:32] Gustav Mogensen
Description:
Since mysqld lacks audit-logging, I let the mysqld general_log (query log) log to a named pipe/socket/fifo-file and from that socket I withdraw Connect- and Quit-information. 
Almost everytime mysqld is shutdown or "flush logs" is performed I get:
mysql> flush logs;
ERROR 27 (HY000): Can't sync file '/var/log/mysql/query.fifo' to disk (Errcode: 22)

* I can't find the ERROR in the manual.
* I seems that mysqld has opened the file for read/write, but IMHO it should only open it for appening (a small potential securityrisk, a hacker inside mysql could teorytical erase logginginfomation).
* You can't set general_log_file to an existing fifo-file. You have to set the variable first, then create the fifo-file and thereafter turn on logging.

How to repeat:
mysql> set general_log=0;
mysql> set global general_log_file='/tmp/query.fifo';
bash> mkfifo -m 0666 /tmp/query.fifo 
bash> while (cat  /tmp/query.fifo >> /dev/null) ; do echo  ; done &
mysql> set global general_log=1;
mysql> flush logs;
ERROR 27 (HY000): Can't sync file '/tmp/query.fifo' to disk (Errcode: 22)

Suggested fix:
Put on wishlist: auditlogging!

Open general_log_file for appending only.
[31 Jan 2011 14:35] Gustav Mogensen
Here is the error when setting general_log_file to an existing fifo:
mysql> set global general_log_file='/var/log/mysql/query.fifo';
ERROR 1231 (42000): Variable 'general_log_file' can't be set to the value of '/var/log/mysql/query.fifo'
[25 Mar 2011 1:41] Sveta Smirnova
thank you for the report.

Verified almost as described, although debug server crashes when trying to turn general_log to on. Error log contains "mf_iocache.c:189: failed assertion `seek_offset == 0'"
[22 Sep 2014 20:50] MySQL Verification Team
https://bugs.mysql.com/bug.php?id=74007 is a duplicate