In mysql.php ignore SIGINT
authorTim Starling <tstarling@wikimedia.org>
Wed, 18 Jul 2018 05:47:23 +0000 (15:47 +1000)
committerTim Starling <tstarling@wikimedia.org>
Wed, 18 Jul 2018 05:57:15 +0000 (15:57 +1000)
Every foreground process with the terminal open will receive SIGINT when
the interrupt key is pressed. But mysql handles SIGINT and kills the
running query, we don't want the wrapper to exit in that case. So,
ignore SIGINT while mysql is running. This is similar to how a shell
deals with this problem.

The other options would have been:

* Close the filehandles in PHP after forking (probably impossible)
* Use pcntl_exec() so that PHP isn't running (more complicated and
  requires the pcntl extension anyway)
* Clear termcap ISIG flag (probably would have broken mysql)

Bug: T199152
Change-Id: I7660cd24e036fbe3fe36d12563ffe1c1fa2360d0

maintenance/mysql.php

index 6d0882a..1b575bb 100644 (file)
@@ -165,6 +165,12 @@ class MysqlMaintenance extends Maintenance {
 
                $args = array_merge( $args, $this->mArgs );
 
+               // Ignore SIGINT if possible, otherwise the wrapper terminates when the user presses
+               // ctrl-C to kill a query.
+               if ( function_exists( 'pcntl_signal' ) ) {
+                       pcntl_signal( SIGINT, SIG_IGN );
+               }
+
                $pipes = [];
                $proc = proc_open( Shell::escape( $args ), $desc, $pipes );
                if ( $proc === false ) {