List:Internals« Previous MessageNext Message »
From:reggie Date:August 9 2005 8:30am
Subject:bk commit into 5.0 tree (reggie:1.1965)
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of reggie. When reggie 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://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.1965 05/08/09 02:29:55 reggie@stripped +3 -0
  changes to IM that came from Petr and JimW's review.

  server-tools/instance-manager/options.cc
    1.22 05/08/09 02:29:39 reggie@stripped +31 -52
    remove the malloc for default password filename on Windows and replace
    with statically allocated memory.
    
    default Options:saved_argv to NULL so that we will know if we need
    to free it in cleanup()
    
    setup the default config file location for Windows inside the
    setup_windows_defaults function and remove this code from load()
    
    rework setup_windows_defaults so that it properly returns 0 on success
    and 1 on error and so it fills in the default location for the
    log file, password file, and config file.

  server-tools/instance-manager/mysqlmanager.cc
    1.14 05/08/09 02:29:39 reggie@stripped +7 -8
    default return value is 1.
    simplify some code bits by just jumping to err on error.
    move options.cleanup inside the err block.  In this case, the err block
    is more than just an error block.  It is the terminating block
    for both error and success.  You set return_value to 0 for success
    or leave it as 1 for failure.  This simplies this function a bit.

  server-tools/instance-manager/IMService.cpp
    1.5 05/08/09 02:29:39 reggie@stripped +3 -3
    make sure HandleServiceOptions returns 0 on success and 1 on failure

# 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:	reggie
# Host:	linux.site
# Root:	/home/reggie/bk/mysql-5.0-new

--- 1.13/server-tools/instance-manager/mysqlmanager.cc	2005-08-03 15:24:33 -06:00
+++ 1.14/server-tools/instance-manager/mysqlmanager.cc	2005-08-09 02:29:39 -06:00
@@ -79,6 +79,7 @@
 
 int main(int argc, char *argv[])
 {
+  int return_value= 1;
   init_environment(argv[0]);
   Options options;
   struct passwd *user_info;
@@ -90,10 +91,7 @@
   if ((user_info= check_user(options.user)))
   {
       if (set_user(options.user, user_info))
-      {
-        options.cleanup();
         goto err;
-      }
   }
 
   if (options.run_as_service)
@@ -105,17 +103,18 @@
   }
 #else
 #ifdef NDEBUG
-  return HandleServiceOptions(options);
+  return_value= HandleServiceOptions(options);
+  goto err;   /* this is not always an error but we reuse the label */
 #endif
 #endif
 
   manager(options);
-  options.cleanup();
-  my_end(0);
-  return 0;
+  return_value= 0;
+
 err:
+  options.cleanup();
   my_end(0);
-  return 1;
+  return return_value;
 }
 
 /******************* Auxilary functions implementation **********************/

--- 1.21/server-tools/instance-manager/options.cc	2005-08-05 12:44:46 -06:00
+++ 1.22/server-tools/instance-manager/options.cc	2005-08-09 02:29:39 -06:00
@@ -30,18 +30,20 @@
 #define QUOTE2(x) #x
 #define QUOTE(x) QUOTE2(x)
 
-const char *default_password_file_name= QUOTE(DEFAULT_PASSWORD_FILE_NAME);
-const char *default_log_file_name= QUOTE(DEFAULT_LOG_FILE_NAME);
 #ifdef __WIN__
-char windows_config_file[FN_REFLEN];
-
 char Options::install_as_service;
 char Options::remove_service;
+char windows_config_file[FN_REFLEN];
+char default_password_file_name[FN_REFLEN];
+char default_log_file_name[FN_REFLEN];
+const char *Options::config_file= windows_config_file;
 #else
 char Options::run_as_service;
 const char *Options::user= 0;                   /* No default value */
-#endif
+const char *default_password_file_name= QUOTE(DEFAULT_PASSWORD_FILE_NAME);
+const char *default_log_file_name= QUOTE(DEFAULT_LOG_FILE_NAME);
 const char *Options::config_file= QUOTE(DEFAULT_CONFIG_FILE);
+#endif
 const char *Options::log_file_name= default_log_file_name;
 const char *Options::pid_file_name= QUOTE(DEFAULT_PID_FILE_NAME);
 const char *Options::socket_file_name= QUOTE(DEFAULT_SOCKET_FILE_NAME);
@@ -51,7 +53,7 @@
 uint Options::monitoring_interval= DEFAULT_MONITORING_INTERVAL;
 uint Options::port_number= DEFAULT_PORT;
 /* just to declare */
-char **Options::saved_argv;
+char **Options::saved_argv= NULL;
 
 /*
   List of options, accepted by the instance manager.
@@ -262,30 +264,8 @@
   }
 
 #ifdef __WIN__
-  setup_windows_defaults(*argv);
-
-  /*
-    On Windows, there are two possibilities.  Either we are given
-    a defaults file on the command line or we use the my.ini file
-    that is in our app dir
-  */
-  if (Options::config_file == NULL)
-  {
-    char *filename;
-    static const char default_win_config_file_name[]= "\\my.ini";
-
-    if (!GetModuleFileName(NULL, windows_config_file,
-                           sizeof(windows_config_file)))
-      goto err;
-
-    filename= strrchr(windows_config_file, "\\");
-    /*
-      Don't check for the overflow as strlen("\\my.ini") is less
-      then strlen("mysqlmanager") (the binary name)
-    */
-    strcpy(filename, default_win_config_file_name);
-    Options::config_file= windows_config_file;
-  }
+  if (setup_windows_defaults())
+    goto err;
 #endif
 
   /* config-file options are prepended to command-line ones */
@@ -305,33 +285,32 @@
 void Options::cleanup()
 {
   /* free_defaults returns nothing */
-  free_defaults(Options::saved_argv);
-#ifdef __WIN__
-  free((char*)default_password_file_name);
-#endif
+  if (Options::saved_argv != NULL)
+    free_defaults(Options::saved_argv);
 }
 
 #ifdef __WIN__
 
-char* change_extension(const char *src, const char *newext)
+void Options::setup_windows_defaults()
 {
-  char *dot= (char*)strrchr(src, '.');
-  if (!dot) return (char*)src;
-
-  int newlen= dot-src+strlen(newext)+1;
-  char *temp= (char*)malloc(newlen);
-  bzero(temp, newlen);
-  strncpy(temp, src, dot-src+1);
-  strcat(temp, newext);
-  return temp;
-}
-
-void Options::setup_windows_defaults(const char *progname)
-{
-  Options::password_file_name= default_password_file_name=
-    change_extension(progname, "passwd");
-  Options::log_file_name= default_log_file_name=
-    change_extension(progname, "log");
+  if (!GetModuleFileName(NULL, default_password_file_name,
+                         sizeof(default_password_file_name)))
+    return -1;
+  char *filename = strstr(default_password_file_name, ".exe");
+  strcpy(filename, ".passwd");
+  
+  if (!GetModuleFileName(NULL, default_log_file_name,
+                         sizeof(default_log_file_name)))
+    return -1;
+  filename = strstr(default_log_file_name, ".exe");
+  strcpy(filename, ".log");
+
+  if (!GetModuleFileName(NULL, windows_config_file,
+                         sizeof(windows_config_file)))
+    return -1;
+  char *slash = strrchr(windows_config_file, '\\');
+  strcpy(slash, "\\my.ini");
+  return 0;
 }
 
 #endif

--- 1.4/server-tools/instance-manager/IMService.cpp	2005-08-05 07:03:02 -06:00
+++ 1.5/server-tools/instance-manager/IMService.cpp	2005-08-09 02:29:39 -06:00
@@ -50,7 +50,7 @@
     else
     {
       log_info("Service failed to install\n");
-      ret_val= -1;
+      ret_val= 1;
     }
   }
   else if (options.remove_service)
@@ -62,10 +62,10 @@
     else
     {
       log_info("Service failed to remove\n");
-      ret_val= -1;
+      ret_val= 1;
     }
   }
   else
-    return (int)winService.Init();
+    ret_val= winService.Init() ? 0 : 1;
   return ret_val;
 }
Thread
bk commit into 5.0 tree (reggie:1.1965)reggie9 Aug