List:Commits« Previous MessageNext Message »
From:Magne Mahre Date:January 5 2011 1:56pm
Subject:bzr commit into mysql-trunk branch (magne.mahre:3461) Bug#55730 Bug#58179
View as plain text  
#At file:///export/home/tmp/x/mysql-trunk-58179/ based on revid:nirbhay.choubey@stripped

 3461 Magne Mahre	2011-01-05
      Bug#58179 cannot start mysqld with app verifier
      Bug#55730 kill_server() calls SetEvent on a null handle, 
                 smem_event_connect_request
            
      Application Verifier is a Microsoft tool used for
      detecting certain classes of programming errors.
      In particular, MS Windows OS resource usage is 
      monitored for wrong usage (handles, thread local
      storage, critical sections, ...)
            
      In MySQL 5.5.x, an error was introduced where an
      object on thread local storage was used before the
      TLS and the object was created.
            
      The fix has been to split the mysys initialization
      into additional parts so the different subsystems
      of mysys can be initialized at different stages
      in the database startup sequence.
            
      In addition, Bug#55730 was fixed.  The event handle
      'smem_event_connect_request' is only created if 
      'opt_enable_shared_memory' is set.  When killing the
      server, an event was flagged on the handle
      unconditionally.  Added a test, so it will only be 
      flagged if created.
     @ mysys/my_init.c
        my_basic_init was renamed to my_init_part1
        The rest of mysys initialization is moved
        to my_init_part2.   my_init() now only
        calls my_init_part1() and my_init_part2()
        
        my_init_part1() now calls my_thread_init_part1()
        my_init_part2() call my_thread_init_part2() and
        my_thread init_part3()
     @ mysys/my_thr_init.c
        Thread initialization is split into three
        parts (was two).  my_thread_init_part1()
        initializes 'THR_KEY_mysys', as this must
        be done before you can use debugging
        features.
        
        my_thread_init_part2 is a new name for
        my_thread_basic_global_init
        
        my_thread_init_part3 is mostly just a rename
        for my_thread_global_init.

    modified:
      include/my_pthread.h
      include/my_sys.h
      mysys/my_init.c
      mysys/my_thr_init.c
      sql/mysqld.cc
=== modified file 'include/my_pthread.h'
--- a/include/my_pthread.h	2011-01-04 15:23:59 +0000
+++ b/include/my_pthread.h	2011-01-05 13:56:32 +0000
@@ -794,8 +794,9 @@ extern pthread_mutexattr_t my_errorcheck
 
 typedef ulong my_thread_id;
 
-extern my_bool my_thread_global_init(void);
-extern my_bool my_thread_basic_global_init(void);
+extern my_bool my_thread_init_part1();
+extern my_bool my_thread_init_part2();
+extern my_bool my_thread_init_part3();
 extern void my_thread_basic_global_reinit(void);
 extern void my_thread_global_end(void);
 extern my_bool my_thread_init(void);

=== modified file 'include/my_sys.h'
--- a/include/my_sys.h	2011-01-04 15:23:59 +0000
+++ b/include/my_sys.h	2011-01-05 13:56:32 +0000
@@ -638,7 +638,8 @@ extern int my_error_register(const char*
 extern const char **my_error_unregister(int first, int last);
 extern void my_message(uint my_err, const char *str,myf MyFlags);
 extern void my_message_stderr(uint my_err, const char *str, myf MyFlags);
-extern my_bool my_basic_init(void);
+extern my_bool my_init_part1(void);
+extern my_bool my_init_part2(void);
 extern my_bool my_init(void);
 extern void my_end(int infoflag);
 extern int my_redel(const char *from, const char *to, int MyFlags);

=== modified file 'mysys/my_init.c'
--- a/mysys/my_init.c	2011-01-04 15:23:59 +0000
+++ b/mysys/my_init.c	2011-01-05 13:56:32 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
+/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -37,8 +37,8 @@ static my_bool win32_init_tcp_ip();
 #define SCALE_USEC      10000
 
 my_bool my_init_done= 0;
-/** True if @c my_basic_init() has been called. */
-my_bool my_basic_init_done= 0;
+/** True if @c my_init_part1() has been called. */
+my_bool my_init_part1_done= 0;
 uint	mysys_usage_id= 0;              /* Incremented for each my_init() */
 ulong   my_thread_stack_size= 65536;
 
@@ -63,16 +63,18 @@ static MYSQL_FILE instrumented_stdin;
   - read configuration files,
   - parse command lines arguments.
   To complete the mysys initialisation,
-  call my_init().
-  @return 0 on success
+  call my_init_part2().
+  @return Initialization result
+    @retval 0 Success
+    @retval 1 Failed
 */
-my_bool my_basic_init(void)
+my_bool my_init_part1(void)
 {
   char * str;
 
-  if (my_basic_init_done)
+  if (my_init_part1_done)
     return 0;
-  my_basic_init_done= 1;
+  my_init_part1_done= 1;
 
   mysys_usage_id++;
   my_umask= 0660;                       /* Default umask for new files */
@@ -91,7 +93,8 @@ my_bool my_basic_init(void)
   instrumented_stdin.m_psi= NULL;       /* not yet instrumented */
   mysql_stdin= & instrumented_stdin;
 
-  if (my_thread_global_init())
+  /* initalize THR_KEY_mysys */
+  if (my_thread_init_part1())
     return 1;
 
 #if defined(SAFE_MUTEX)
@@ -105,7 +108,7 @@ my_bool my_basic_init(void)
 #if defined(HAVE_PTHREAD_INIT)
   pthread_init();			/* Must be called before DBUG_ENTER */
 #endif
-  if (my_thread_basic_global_init())
+  if (my_thread_init_part2())
     return 1;
 
   /* $HOME is needed early to parse configuration files located in ~/ */
@@ -134,25 +137,45 @@ my_bool my_init(void)
 
   my_init_done= 1;
 
-  if (my_basic_init())
+  if (my_init_part1())
     return 1;
 
-  if (my_thread_global_init())
+  if (my_init_part2())
     return 1;
 
-  {
-    DBUG_ENTER("my_init");
-    DBUG_PROCESS((char*) (my_progname ? my_progname : "unknown"));
-    my_win_init();
-    DBUG_PRINT("exit", ("home: '%s'", home_dir));
-#ifdef __WIN__
-    win32_init_tcp_ip();
-#endif
-    DBUG_RETURN(0);
-  }
+  return 0;
 } /* my_init */
 
 
+/**
+  Second part of my_sys initalization
+  (mutexes, condition variables,  critical sections)
+
+  @returns Initialization result
+    @retval 0  Success
+    @retval 1  Failed
+*/
+my_bool my_init_part2()
+{
+  DBUG_ENTER("my_init_part2");
+  DBUG_PROCESS((char*) (my_progname ? my_progname : "unknown"));
+
+  if (my_thread_init_part2())
+    DBUG_RETURN(1);
+
+  my_win_init();
+  DBUG_PRINT("exit", ("home: '%s'", home_dir));
+#ifdef _WIN32
+  win32_init_tcp_ip();
+#endif
+
+  if (my_thread_init_part3())
+    return 1;
+
+  DBUG_RETURN(0);
+} /* my_init_part2 */
+
+
 	/* End my_sys */
 
 void my_end(int infoflag)
@@ -256,7 +279,7 @@ Voluntary context switches %ld, Involunt
 #endif /* __WIN__ */
 
   my_init_done=0;
-  my_basic_init_done= 0;
+  my_init_part1_done= 0;
 } /* my_end */
 
 

=== modified file 'mysys/my_thr_init.c'
--- a/mysys/my_thr_init.c	2011-01-04 15:23:59 +0000
+++ b/mysys/my_thr_init.c	2011-01-05 13:56:32 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc
+/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -67,7 +67,30 @@ nptl_pthread_exit_hack_handler(void *arg
 static uint get_thread_lib(void);
 
 /** True if @c my_thread_basic_global_init() has been called. */
-static my_bool my_thread_basic_global_init_done= 0;
+static my_bool my_thread_init_part2_done= 0;
+
+
+/**
+  Initialize the THR_KEY_mysys key
+
+  @returns Intialization result
+    @retval 0 Success
+    @retval 1 Failed
+  
+  @sa my_init_part1
+  @sa my_thread_basic_global_reinit
+*/
+my_bool my_thread_init_part1()
+{
+  int pth_ret;
+  if ((pth_ret= pthread_key_create(&THR_KEY_mysys, NULL)) != 0)
+  {
+    fprintf(stderr, "Can't initialize threads: error %d\n", pth_ret);
+    return 1;
+  }
+  return 0;
+}
+
 
 /**
   Perform a minimal initialisation of mysys, when compiled with threads.
@@ -76,16 +99,14 @@ static my_bool my_thread_basic_global_in
   - perform file operations
   - use charsets
   - use my_errno
-  @sa my_basic_init
+  @sa my_init_part1
   @sa my_thread_basic_global_reinit
 */
-my_bool my_thread_basic_global_init(void)
+my_bool my_thread_init_part2(void)
 {
-  int pth_ret;
-
-  if (my_thread_basic_global_init_done)
+  if (my_thread_init_part2_done)
     return 0;
-  my_thread_basic_global_init_done= 1;
+  my_thread_init_part2_done= 1;
 
 #ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
   /*
@@ -116,11 +137,6 @@ my_bool my_thread_basic_global_init(void
   mysql_mutex_init(key_THR_LOCK_charset, &THR_LOCK_charset, MY_MUTEX_INIT_FAST);
   mysql_mutex_init(key_THR_LOCK_threads, &THR_LOCK_threads, MY_MUTEX_INIT_FAST);
 
-  if ((pth_ret= pthread_key_create(&THR_KEY_mysys, NULL)) != 0)
-  {
-    fprintf(stderr, "Can't initialize threads: error %d\n", pth_ret);
-    return 1;
-  }
 
   if (my_thread_init())
     return 1;
@@ -140,7 +156,7 @@ void my_thread_basic_global_reinit(void)
 {
   struct st_my_thread_var *tmp;
 
-  DBUG_ASSERT(my_thread_basic_global_init_done);
+  DBUG_ASSERT(my_thread_init_part2_done);
 
 #ifdef HAVE_PSI_INTERFACE
   my_init_mysys_psi_keys();
@@ -181,9 +197,36 @@ void my_thread_basic_global_reinit(void)
 
 my_bool my_thread_global_init(void)
 {
-  if (my_thread_basic_global_init())
+  if (my_thread_init_part1())
+    return 1;
+
+  if (my_thread_init_part2())
+    return 1;
+
+  if (my_thread_init_part3())
+    return 1;
+
+  if (my_thread_init())
+  {
+    my_thread_global_end();			/* Clean up */
     return 1;
+  }
+  return 0;
+}
+
 
+/**
+  Initialize rest of mysys mutexes
+
+  @returns Intialization result
+    @retval 0 Success
+    @retval 1 Failed
+  
+  @sa my_init_part2
+  @sa my_thread_basic_global_reinit
+*/
+my_bool my_thread_init_part3()
+{
   thd_lib_detected= get_thread_lib();
 
 #ifdef TARGET_OS_LINUX
@@ -233,16 +276,11 @@ my_bool my_thread_global_init(void)
 #ifdef _MSC_VER
   install_sigabrt_handler();
 #endif
-
-  if (my_thread_init())
-  {
-    my_thread_global_end();			/* Clean up */
-    return 1;
-  }
   return 0;
 }
 
 
+
 void my_thread_global_end(void)
 {
   struct timespec abstime;
@@ -302,7 +340,7 @@ void my_thread_global_end(void)
   mysql_mutex_destroy(&LOCK_gethostbyname_r);
 #endif
 
-  my_thread_basic_global_init_done= 0;
+  my_thread_init_part2_done= 0;
 }
 
 static my_thread_id thread_id= 0;

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2011-01-03 15:05:36 +0000
+++ b/sql/mysqld.cc	2011-01-05 13:56:32 +0000
@@ -1,4 +1,4 @@
-/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -1273,15 +1273,18 @@ static void __cdecl kill_server(int sig_
   else
     sql_print_error(ER_DEFAULT(ER_GOT_SIGNAL),my_progname,sig); /* purecov: inspected */
 
-#if defined(HAVE_SMEM) && defined(__WIN__)    
+#if defined(HAVE_SMEM) && defined(_WIN32)    
   /*    
    Send event to smem_event_connect_request for aborting    
    */    
-  if (!SetEvent(smem_event_connect_request))    
-  {      
-	  DBUG_PRINT("error",
-		("Got error: %ld from SetEvent of smem_event_connect_request",
-		 GetLastError()));    
+  if (opt_enable_shared_memory)
+  {
+    if (!SetEvent(smem_event_connect_request))    
+    {      
+      DBUG_PRINT("error",
+                 ("Got error: %ld from SetEvent of smem_event_connect_request",
+                  GetLastError()));    
+    }
   }
 #endif  
   
@@ -4424,22 +4427,28 @@ static void test_lc_time_sz()
 }
 #endif//DBUG_OFF
 
-#ifdef __WIN__
+#ifdef _WIN32
 int win_main(int argc, char **argv)
 #else
 int mysqld_main(int argc, char **argv)
 #endif
 {
+
+#ifndef _WIN32
   /*
     Perform basic thread library and malloc initialization,
     to be able to read defaults files and parse options.
+
+    For WIN32, this code is executed in the win32 specific
+    mysqld_main
   */
   my_progname= argv[0];
-  if (my_basic_init())
+  if (my_init_part1())
   {
-    fprintf(stderr, "my_basic_init() failed.");
+    fprintf(stderr, "my_init_part1() failed.");
     return 1;
   }
+#endif // _WIN32
 
   orig_argc= argc;
   orig_argv= argv;
@@ -4541,7 +4550,12 @@ int mysqld_main(int argc, char **argv)
   }
 #endif /* HAVE_PSI_INTERFACE */
 
-  my_init();                                   // init my_sys library & pthreads
+  if (my_init_part2())                                   // init my_sys library & pthreads
+  {
+    fprintf(stderr, "my_init_part2() failed.");
+    return 1;
+  }
+
   init_error_log_mutex();
 
   /* Set signal used to kill MySQL */
@@ -4982,6 +4996,19 @@ int mysqld_main(int argc, char **argv)
   if (Service.GetOS())	/* true NT family */
   {
     char file_path[FN_REFLEN];
+
+    /*
+      Perform basic thread library and malloc initialization,
+      to be able to read defaults files and parse options.
+    */
+    my_progname= argv[0];
+    if (my_init_part1())
+    {
+      fprintf(stderr, "my_init_part1() failed.");
+      return 1;
+    }
+
+    
     my_path(file_path, argv[0], "");		      /* Find name in path */
     fn_format(file_path,argv[0],file_path,"",
 	      MY_REPLACE_DIR | MY_UNPACK_FILENAME | MY_RESOLVE_SYMLINKS);


Attachment: [text/bzr-bundle] bzr/magne.mahre@oracle.com-20110105135632-g9h0ax7b8f1tvz7c.bundle
Thread
bzr commit into mysql-trunk branch (magne.mahre:3461) Bug#55730 Bug#58179Magne Mahre5 Jan
  • Re: bzr commit into mysql-trunk branch (magne.mahre:3461) Bug#55730Bug#58179Magnus Blåudd5 Jan
    • Re: bzr commit into mysql-trunk branch (magne.mahre:3461) Bug#55730Bug#58179Magne Mæhre5 Jan
      • Re: bzr commit into mysql-trunk branch (magne.mahre:3461) Bug#55730Bug#58179Magnus Blåudd5 Jan
  • Re: bzr commit into mysql-trunk branch (magne.mahre:3461) Bug#55730Bug#58179Davi Arnaut10 Jan