Mysql: kill query on timeout

We have an SQL timeout, but it wasn't actually killing the query when
it times out. This is problem when issuing the FLUSH TABLES command
because it occasionally locks up the database if there is a
long-running write query.

Now, we kill the query when the timeout hits which also kills it upon
CTRL-C'ing

See here for the problem (fixes #23):
https://github.com/alestic/ec2-consistent-snapshot/issues/23

Got the idea for the fix from here:
http://www.perlmonks.org/?node_id=885620

I've tested the following:

1. Call: sql_timeout_retry("SELECT SLEEP(60);", 0.5, 10, 5); after
   connecting.
2. Check the processlist while this is happening:
   Before: We see the query in the list all the time because the
           timeout *doesn't* stop the query
   After:  query is rarely seen in the list cause it times out and is
           killed after 0.5s
3. Interrupt the process (Ctrl-C) while it's happening
   Before: Query is still in the processlist until it finishes
   After: Query is killed when the process is killed.
It seems you're correct; though I don't know if that helps here. The potential badness (query is successful but we timeout before acknowledging, either trying again or dying) isn't prevented by the double-eval. Because we set the signal handler outside the loop, the alarm will never trigger without our handler being set.

There's no way to check if a query was successful if our timeout happened in the narrow gap after the query finished, but before the `do()` method returned, so there is a remote possibility that a `READ LOCK` could succeed but we think it failed, so we try again. I just experimented and these global locks don't stack up, so we'll only ever have one lock.