Bug #80542 Should notify users when ignoring their option files
Submitted: 27 Feb 2016 21:22 Modified: 28 Feb 2016 22:33
Reporter: Tianyin Xu Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Logging Severity:S3 (Non-critical)
Version:5.7.11 OS:Any
Assigned to: CPU Architecture:Any

[27 Feb 2016 21:22] Tianyin Xu
Description:
During startup, MySQL checks option files (e.g., my.cnf) in a few default locations described below, 
http://dev.mysql.com/doc/refman/5.7/en/option-files.html

If the permissions of any option file is wrong, MySQL will ignore the file. However, MySQL does not always notify users such ignorance. 

If the permission is world writeable, MySQL does print warnings such as 
[Warning] World-writable config file '/etc/my.cnf' is ignored.
(printed in check_file_permissions() in mysys_ssl/my_default.cc)

But, for other permission problems, MySQL ignores the file silently. 

This cause many confusing and "mysterious" cases as the users change the configuration settings but do not observe the corresponding effect. Here lists a few real-world complaints,
http://serverfault.com/questions/293282/my-cnf-values-not-applying-optimizing-mysql-on-cen...
http://serverfault.com/questions/341958/centos-percona-mysql-not-reading-etc-my-cnf
http://serverfault.com/questions/246693/root-users-and-mysql-sudo-mysql-vs-root-my-cnf

I hope MySQL can have the consistent behavior ---warning users that the option file is ignored.  

 

How to repeat:
Touch an option file /etc/my.cnf, put some random string in it. If the permission is correct, MySQL will complain and refuse to start. 

Then, chmod 000 /etc/my.cnf, start MySQL and you won't find any warning telling you that there's errors in the file. 

Suggested fix:
The fix is relatively straightforward ---adding the corresponding warning messages just like what we're doing when the option file is world writable. 

Here is a demo patch,

--- mysql-5.7.11/mysys_ssl/my_default.cc	2016-02-01 15:31:58.000000000 -0800
+++ mysql-5.7.11/mysys_ssl/my_default.cc	2016-02-27 12:41:43.540901477 -0800
@@ -901,12 +901,20 @@
   {
     if ( !(fp = mysql_file_fopen(key_file_cnf, name, (O_RDONLY | O_BINARY),
                                  MYF(0))))
+    {
+      my_message_local(WARNING_LEVEL, 
+          "Ignore the config file '%s' as we cannot open it.", name);
       return 1;                                 /* Ignore wrong files. */
+    }
   }
   else
   {
     if ( !(fp = mysql_file_fopen(key_file_cnf, name, O_RDONLY, MYF(0))))
+    {
+      my_message_local(WARNING_LEVEL, 
+          "Ignore the config file '%s' as we cannot open it.", name);
       return 1;                                 /* Ignore wrong files */
+    }
   }
 
   while (mysql_file_getline(buff, sizeof(buff) - 1, fp))
[28 Feb 2016 14:07] MySQL Verification Team
Hello Tianyin,

Thank you for the report and contribution.
Verified as described with 5.7.11 build.

Thanks,
Umesh
[28 Feb 2016 14:08] MySQL Verification Team
Please note that in order to submit contributions you must first sign the Oracle Contribution Agreement (OCA). For additional information please check http://www.oracle.com/technetwork/community/oca-486395.html.
If you have any questions, please contact the MySQL community team.
[28 Feb 2016 22:33] Tianyin Xu
Gotcha! Thanks a lot, Umesh! Really appreciate your efforts reviewing the reports. 

I'll definitely check our OCA. For this case, the patch is just for the purpose of demonstration, though it passed all the tests.