[debian-mysql] Bug#527623: mysql-server-5.0: 38_scripts__mysqld_safe.sh__signals.dpatch is inherently

Stephane Chazelas stephane.chazelas at seebyte.com
Tue Jun 9 10:13:25 UTC 2009


2009-05-12 12:21:39 -0400, Mathias Gug:
> Here is a patch applied in Ubuntu that adresses the issue.
> 
> The problem comes from the fact that mysqld_safe starts mysqld and then
> waits for its crash. However installing a trap for SIGHUP makes the wait
> command return immediately when a SIGHUP is received by mysqld_safe.
> This leads mysqld_safe to proceed and kill the remaining mysqld process
> (which hasn't crashed). The proposed fix is to add a wait command to the
> trap.
[...]
> diff -u mysql-dfsg-5.0-5.1.30really5.0.75/debian/patches/38_scripts__mysqld_safe.sh__signals.dpatch mysql-dfsg-5.0-5.1.30really5.0.75/debian/patches/38_scripts__mysqld_safe.sh__signals.dpatch
> --- mysql-dfsg-5.0-5.1.30really5.0.75/debian/patches/38_scripts__mysqld_safe.sh__signals.dpatch
> +++ mysql-dfsg-5.0-5.1.30really5.0.75/debian/patches/38_scripts__mysqld_safe.sh__signals.dpatch
> @@ -24,7 +24,7 @@
>  +# From now on, we catch signals to do a proper shutdown of mysqld
>  +# when signalled to do so.
>  +#
> -+trap '/usr/bin/mysqladmin --defaults-extra-file=/etc/mysql/debian.cnf refresh' 1 # HUP
> ++trap '/usr/bin/mysqladmin --defaults-extra-file=/etc/mysql/debian.cnf refresh & wait' 1 # HUP
>  +trap '/usr/bin/mysqladmin --defaults-extra-file=/etc/mysql/debian.cnf shutdown' 2 3 15 # INT QUIT and TERM
>  +
>  +#

Hiya,

that patch is still wrong.

The first time a HUP is received, we run the code in the trap
and call wait which will wait for both the refresh command and
the mysqld one.

But we won't return from that trap until mysqld dies, and in the
trap the HUP signal is blocked, which means any subsequent
HUP will not be handled.

A better way could be to implement some proper event handling as in:

trap : HUP INT QUIT TERM
while :; do
  action=
  mysqld ... & 
  while :; do
    signal=NONE
    wait || signal=$(kill -l "$?")

    case $signal in
      (INT|TERM|QUIT) mysqladmin ... shutdown; exit;;
      (HUP) mysqladmin ... refresh;;
      (NONE) break;; # mysqld died
      (*) unexpected ... die;;
    esac
  esac
done

Best regards,
Stephane





More information about the pkg-mysql-maint mailing list