List:Commits« Previous MessageNext Message »
From:Nirbhay Choubey Date:April 28 2011 9:29pm
Subject:bzr commit into mysql-trunk branch (nirbhay.choubey:3339) Bug#11760134
View as plain text  
#At file:///home/nirbhay/Project/mysql/repo/bugs/mysql-trunk.52515/ based on revid:davi.arnaut@stripped

 3339 Nirbhay Choubey	2011-04-29
      Bug#11760134 - 52515: mysql sessions are not
                     terminated properly.
      
      The mysql command line client was not reacting on
      closing its controlling terminal.
      
      Added windows specific code to handle the console events.
      Added a handler for the SIGHUP to gracefully shutdown the
      running statement. Made sure the windows specific code
      handles correctly Ctrl-C.
     @ client/mysql.cc
        Bug#11760134 - 52515: mysql sessions are not
                       terminated properly.
        
        Added windows specific code to handle different
        console events.

    modified:
      client/mysql.cc*
=== modified file 'client/mysql.cc' (properties changed: -x to +x)
--- a/client/mysql.cc	2011-03-09 20:54:55 +0000
+++ b/client/mysql.cc	2011-04-28 21:29:12 +0000
@@ -1096,12 +1096,34 @@ static void end_timer(ulong start_time,c
 static void mysql_end_timer(ulong start_time,char *buff);
 static void nice_time(double sec,char *buff,bool part_second);
 extern "C" sig_handler mysql_end(int sig);
-extern "C" sig_handler handle_sigint(int sig);
+extern "C" sig_handler handle_kill_signal(int sig);
 #if defined(HAVE_TERMIOS_H) && defined(GWINSZ_IN_SYS_IOCTL)
 static sig_handler window_resize(int sig);
 #endif
 
 
+#ifdef _WIN32
+BOOL windows_ctrl_handler(DWORD fdwCtrlType)
+{
+  switch (fdwCtrlType)
+  {
+  case CTRL_C_EVENT:
+  case CTRL_BREAK_EVENT:
+    if (!opt_sigint_ignore)
+      handle_kill_signal(SIGINT);
+    /* Indicate that signal has beed handled. */  
+    return TRUE;
+  case CTRL_CLOSE_EVENT:
+  case CTRL_LOGOFF_EVENT:
+  case CTRL_SHUTDOWN_EVENT:
+    handle_kill_signal(SIGINT + 1);
+  }
+  /* Pass signal to the next control handler function. */
+  return FALSE;
+}
+#endif
+
+
 int main(int argc,char *argv[])
 {
   char buff[80];
@@ -1198,11 +1220,17 @@ int main(int argc,char *argv[])
   if (!status.batch)
     ignore_errors=1;				// Don't abort monitor
 
+#ifndef _WIN32
   if (opt_sigint_ignore)
     signal(SIGINT, SIG_IGN);
   else
-    signal(SIGINT, handle_sigint);              // Catch SIGINT to clean up
+    signal(SIGINT, handle_kill_signal);         // Catch SIGINT to clean up
   signal(SIGQUIT, mysql_end);			// Catch SIGQUIT to clean up
+  signal(SIGHUP, handle_kill_signal);         // Catch SIGHUP to clean up
+#else
+  SetConsoleCtrlHandler((PHANDLER_ROUTINE) windows_ctrl_handler, TRUE);
+#endif
+
 
 #if defined(HAVE_TERMIOS_H) && defined(GWINSZ_IN_SYS_IOCTL)
   /* Readline will call this if it installs a handler */
@@ -1329,16 +1357,17 @@ sig_handler mysql_end(int sig)
   If query is in process, kill query
   no query in process, terminate like previous behavior
  */
-sig_handler handle_sigint(int sig)
+sig_handler handle_kill_signal(int sig)
 {
   char kill_buffer[40];
   MYSQL *kill_mysql= NULL;
+  const char *reason = sig == SIGINT ? "Ctrl-C" : "terminal close";
 
   /* terminate if no query being executed, or we already tried interrupting */
   /* terminate if no query being executed, or we already tried interrupting */
   if (!executing_query || (interrupted_query == 2))
   {
-    tee_fprintf(stdout, "Ctrl-C -- exit!\n");
+    tee_fprintf(stdout, "%s -- exit!\n", reason);
     goto err;
   }
 
@@ -1346,7 +1375,7 @@ sig_handler handle_sigint(int sig)
   if (!mysql_real_connect(kill_mysql,current_host, current_user, opt_password,
                           "", opt_mysql_port, opt_mysql_unix_port,0))
   {
-    tee_fprintf(stdout, "Ctrl-C -- sorry, cannot connect to server to kill query, giving up ...\n");
+    tee_fprintf(stdout, "%s -- sorry, cannot connect to server to kill query, giving up ...\n", reason);
     goto err;
   }
 
@@ -1360,10 +1389,11 @@ sig_handler handle_sigint(int sig)
   sprintf(kill_buffer, "KILL %s%lu",
           (interrupted_query == 1) ? "QUERY " : "",
           mysql_thread_id(&mysql));
-  tee_fprintf(stdout, "Ctrl-C -- sending \"%s\" to server ...\n", kill_buffer);
+  tee_fprintf(stdout, "%s -- sending \"%s\" to server ...\n", 
+              reason, kill_buffer);
   mysql_real_query(kill_mysql, kill_buffer, (uint) strlen(kill_buffer));
   mysql_close(kill_mysql);
-  tee_fprintf(stdout, "Ctrl-C -- query aborted.\n");
+  tee_fprintf(stdout, "%s -- query aborted.\n", reason);
 
   return;
 


Attachment: [text/bzr-bundle] bzr/nirbhay.choubey@oracle.com-20110428212912-w67n3yetoz9vdw1d.bundle
Thread
bzr commit into mysql-trunk branch (nirbhay.choubey:3339) Bug#11760134Nirbhay Choubey28 Apr