Bug #36514 mysqld_safe gives chown: 'Operation not permitted' for error log on OSX
Submitted: 5 May 2008 18:46 Modified: 13 Jan 2010 5:01
Reporter: Marcos Palacios Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: General Severity:S3 (Non-critical)
Version:5.0 OS:MacOS (10.5.2)
Assigned to: CPU Architecture:Any

[5 May 2008 18:46] Marcos Palacios
Description:
Running 'mysqlmonitorctl.sh start' gives this output:
./mysqlmonitorctl.sh : mysql  started
chown: /Applications/mysql/enterprise/monitor/mysql/data/mysqld.log: Operation not permitted
Starting mysqld daemon with databases from /Applications/mysql/enterprise/monitor/mysql/data/
Using CATALINA_BASE:   /Applications/mysql/enterprise/monitor/apache-tomcat
Using CATALINA_HOME:   /Applications/mysql/enterprise/monitor/apache-tomcat
Using CATALINA_TMPDIR: /Applications/mysql/enterprise/monitor/apache-tomcat/temp
Using JRE_HOME:       /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home

Then, giving 'mysqlmonitorctl.sh status' gives:
MySQL Network MySQL is running
MySQL Network Tomcat is running

So, "chown: /Applications/mysql/enterprise/monitor/mysql/data/mysqld.log: Operation not permitted" seems wrong. 
I am not 'root' but am a member of the 'admin' group and actually own the file after the command.

How to repeat:
1. Login to OS X 10.5 as a user who is not root but is a member of the 'admin' group.
2. cd to the monitor directory.
3. Issue 'mysqlmonitorctl.sh start' and observe the output.
[7 May 2008 15:45] BitRock Merlin
The problem is located inside the "mysqld_safe" script, where there is a logic to determine whether the current user is root or not. This involves checking if the root directory "/" is writable. The problem is that the OS X administrator users (not the same than being the root user) are allowed to write to "/", therefore being identified by "mysqld_safe" as the root user, but they are not allowed to perform any "chown" operation, so that's why we obtain the warning message.

if test -w / -o "$USER" = "root"
then
 ...
 # If we are root, change the err log to the right user.                                                                                                     
 touch $err_log; chown $user $err_log
 ...
fi

A possible solution is to replace the root check with the "id" command check. We have not use the 'id -u' option because Solaris does not support it.

if [ 'id|sed -e s/uid=//g -e s/\(.*//g' = 0 ]
then
 ...
 # If we are root, change the err log to the right user.                                                                                                                    
 touch $err_log; chown $user $err_log
 ...
fi
[8 Jun 2008 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[9 Jun 2008 7:28] BitRock Merlin
We didn't receive a response to our explanation and the suggested solution, so setting again to "Need Feedback"
[7 Jul 2008 18:01] Mark Leith
This represents a problem with mysqld_safe on OSX on all installations, not just those of MEM, so I am re-classifying this bug for the mainstream server. 

BitRock - please do move ahead with your suggested solution, by modifying the mysqld_safe we supply, your solution seems sound to me for the platforms MEM supports. 

We need to assess whether this change is appropriate for all of the other platforms that we support for the mainline server as well however. Once you have made your change, please let us know so that QA can verify the fix on Linux, Solaris and OSX, and then pass this over to the server developers to be rectified in the mainstream server. 

Thanks for the suggested solution.
[19 Sep 2008 18:32] BitRock Merlin
Patch sent to Keith.
[23 Sep 2008 1:41] Keith Russell
Patch installed in versions => 2.0.0.7058.
[3 Dec 2008 13:30] Georgi Kodinov
Was the patch doing what's expected from it ? 
Can you please attach it to the bug report so we can put it in the server distribution ?
[4 Jan 2009 0:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[19 Apr 2010 22:57] Keith Russell
Installed patch as it exist:

USER_OPTION=""
if [ `id|sed -e s/uid=//g -e s/\(.*//g` -eq 0 ]
then
  if test "$user" != "root" -o $SET_USER = 1
  then
    USER_OPTION="--user=$user"
  fi
  # If we are root, change the err log to the right user.
  touch $err_log; chown $user $err_log
  if test -n "$open_files"
  then
    ulimit -n $open_files
    args="--open-files-limit=$open_files $args"
  fi
fi