Bug #47834 init.d script should fail when it has no permission to read PID
Submitted: 5 Oct 2009 13:01
Reporter: Geert Vanderkelen Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: General Severity:S3 (Non-critical)
Version:5.1.39 OS:Linux
Assigned to: CPU Architecture:Any
Tags: init.d

[5 Oct 2009 13:01] Geert Vanderkelen
Description:
Currently the init.d script, when execute as none 'super user' will not fail, but try to shutdown mysqld anyway.

How to repeat:
[geert@cent01 ~]$ /etc/init.d/mysql stop
cat: /var/lib/mysql/cent01.kemuri.net.pid: Permission denied
Shutting down MySQLkill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
..

Suggested fix:
Just test that the pid-file can be read by the current user before doing anything.

    # If the manager pid_file doesn't exist, try the server's
    if test ! -s "$pid_file"
    then
      pid_file=$server_pid_file
      lock_dir=/var/lock/subsys/mysql
    fi

    if ! test -r $pid_file ;
    then
      log_failure_msg "Could not read PID (check permissions)"
      exit 1
    fi