List:Internals« Previous MessageNext Message »
From:sasha Date:February 4 2005 6:28pm
Subject:bk commit into 4.1 tree (sasha:1.1978)
View as plain text  
Below is the list of changes that have just been committed into a local
4.1 repository of sasha. When sasha does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://www.mysql.com/doc/I/n/Installing_source_tree.html

ChangeSet
  1.1978 05/02/04 11:28:56 sasha@stripped +1 -0
  mysqld.cc:
    kill-old-mysqld

  sql/mysqld.cc
    1.482 05/02/04 11:27:55 sasha@stripped +63 -2
    kill-old-mysqld

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	sasha
# Host:	mysql.sashanet.com
# Root:	/reiser-data/oreilly/mysql-4.1

--- 1.481/sql/mysqld.cc	Sun Jul 11 22:38:43 2004
+++ 1.482/sql/mysqld.cc	Fri Feb  4 11:27:55 2005
@@ -259,6 +259,7 @@
 my_bool opt_reckless_slave = 0;
 my_bool opt_enable_named_pipe= 0, opt_debugging= 0;
 my_bool opt_local_infile, opt_external_locking, opt_slave_compressed_protocol;
+my_bool opt_kill_old_mysqld = 0;
 my_bool opt_safe_user_create = 0, opt_no_mix_types = 0;
 my_bool opt_show_slave_auth_info, opt_sql_bin_update = 0;
 my_bool opt_log_slave_updates= 0;
@@ -481,6 +482,7 @@
 static void start_signal_handler(void);
 extern "C" pthread_handler_decl(signal_hand, arg);
 static void mysql_init_variables(void);
+static void kill_old_mysqld(void);
 static void get_options(int argc,char **argv);
 static void set_server_version(void);
 static int init_thread_environment();
@@ -2308,6 +2310,8 @@
   load_defaults(conf_file_name, groups, &argc, &argv);
   defaults_argv=argv;
   get_options(argc,argv);
+ 
+  
   set_server_version();
 
   DBUG_PRINT("info",("%s  Ver %s for %s on %s\n",my_progname,
@@ -2762,7 +2766,11 @@
   if (init_common_variables(MYSQL_CONFIG_NAME,
 			    argc, argv, load_default_groups))
     unireg_abort(1);				// Will do exit
-
+    
+  if (opt_kill_old_mysqld)
+    kill_old_mysqld();
+  
+    
   init_signals();
   if (!(opt_specialflag & SPECIAL_NO_PRIOR))
     my_pthread_setprio(pthread_self(),CONNECT_PRIOR);
@@ -3964,7 +3972,8 @@
   OPT_TIME_FORMAT,
   OPT_DATETIME_FORMAT,
   OPT_LOG_QUERIES_NOT_USING_INDEXES,
-  OPT_DEFAULT_TIME_ZONE
+  OPT_DEFAULT_TIME_ZONE,
+  OPT_KILL_OLD_MYSQLD
 };
 
 
@@ -4172,6 +4181,8 @@
   {"init-file", OPT_INIT_FILE, "Read SQL commands from this file at startup.",
    (gptr*) &opt_init_file, (gptr*) &opt_init_file, 0, GET_STR, REQUIRED_ARG,
    0, 0, 0, 0, 0, 0},
+  {"kill-old-mysqld", OPT_KILL_OLD_MYSQLD, "Kill old instance of mysqld on startup", (gptr*) &opt_kill_old_mysqld, (gptr*) &opt_kill_old_mysqld, 0,
+    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"log", 'l', "Log connections and queries to file.", (gptr*) &opt_logname,
    (gptr*) &opt_logname, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
   {"language", 'L',
@@ -5531,6 +5542,56 @@
 #endif
 }
 
+static void kill_old_mysqld(void)
+{
+  File fd = -1;
+  
+  /* pid value can have no more than 20 digits, 
+   * and we need one extra byte for the new line character
+   */ 
+     
+  char buf[21];
+  char* p;
+  long pid;
+  
+  /* return if we cannot open the file */
+  if ((fd = my_open(pidfile_name,O_RDONLY,MYF(0))) < 0)
+    return; 
+    
+  /* Populate the buffer. For the sake of simplicity we do not deal 
+   * with the case of a partial read, and leave it as an exercise for
+   * the meticulous reader. 
+   */  
+  if (my_read(fd, buf, sizeof(buf), MYF(0)) <= 0)
+    goto err;
+    
+  /* boundary for strchr() */  
+  buf[sizeof(buf) - 1] = 0;
+  
+  /* find the end of line and put a \0 terminator instead */
+  if (!(p = strchr(buf,'\n')))
+    goto err;     
+  *p = 0;
+  
+  if (!(pid = strtol(buf,0,10)))
+    goto err;
+
+  /* Support for Windows is left as an exercise for the reader */      
+#ifndef __WIN__
+  /* A crude kill method with no checks. A more refined one is left 
+   * as an exercise for the reader.
+   */
+  kill(pid, SIGTERM);
+  sleep(5);
+  kill(pid, SIGKILL);
+  sleep(2);
+#endif    
+ 
+  /* Cleanup. Should be executed in all cases, success or error */  
+err:
+  if (fd >= 0)
+    my_close(fd,MYF(0));
+}
 
 extern "C" my_bool
 get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
Thread
bk commit into 4.1 tree (sasha:1.1978)sasha4 Feb