diff options
author | Vladislav Vaintroub <wlad@montyprogram.com> | 2011-02-04 12:20:41 +0100 |
---|---|---|
committer | Vladislav Vaintroub <wlad@montyprogram.com> | 2011-02-04 12:20:41 +0100 |
commit | 614a6dfcd4320600762a9bf39587c4df08a3d9af (patch) | |
tree | 22795e1d2456f7e002448f5aadfba13c4acd21ff /sql | |
parent | edf9757cb846f494e75efe297b863a1a7613976d (diff) | |
download | mariadb-git-614a6dfcd4320600762a9bf39587c4df08a3d9af.tar.gz |
MWL#55: Handle cases where service was installed with
mysqld --install without any parameters.
In such case, service name is always MYSQL, as service
binary path is "path\to\mysqld.exe" "MySQL". Guess data
directory it is either from my.ini (which is assumed to
be in the installation root), or just data directory
under install root.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/mysql_upgrade_service.cc | 28 | ||||
-rw-r--r-- | sql/winservice.c | 87 |
2 files changed, 101 insertions, 14 deletions
diff --git a/sql/mysql_upgrade_service.cc b/sql/mysql_upgrade_service.cc index 0a77608f710..fa5369346e2 100644 --- a/sql/mysql_upgrade_service.cc +++ b/sql/mysql_upgrade_service.cc @@ -36,8 +36,8 @@ #pragma comment(lib, "version") #define USAGETEXT \ -"mysql_upgrade_service.exe Ver 1.42 for Windows\n" \
-"This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n" \
+"mysql_upgrade_service.exe Ver 1.42 for Windows\n" \ +"This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n" \ "and you are welcome to modify and redistribute it under the GPL v2 license\n" \ "Usage: mysql_upgrade_service.exe [OPTIONS]\n" \ "OPTIONS:" @@ -371,6 +371,30 @@ static void change_service_config() my_major, my_minor); } + if(props.inifile[0] == 0) + { + /* + Weird case, no --defaults-file in service definition, need to create one. + */ + char buf[MAX_PATH]; + int i; + + sprintf_s(props.inifile, MAX_PATH, "%s\\my.ini", props.datadir); + + /* + Write datadir to my.ini, after converting backslashes to + unix style slashes. + */ + strcpy_s(buf, MAX_PATH, props.datadir); + for(i=0; buf[i]; i++) + { + if (buf[i] == '\\') + buf[i]= '/'; + } + + WritePrivateProfileString("mysqld", "datadir",buf, props.inifile); + } + /* Remove basedir from defaults file, otherwise the service wont come up in the new version, and will complain about mismatched message file. diff --git a/sql/winservice.c b/sql/winservice.c index 0c238d4d33d..ee29d3556d8 100644 --- a/sql/winservice.c +++ b/sql/winservice.c @@ -76,6 +76,7 @@ int get_mysql_service_properties(const wchar_t *bin_path, wchar_t *file_part; wchar_t **args= NULL; int retval= 1; + BOOL have_inifile; props->datadir[0]= 0; props->inifile[0]= 0; @@ -85,11 +86,28 @@ int get_mysql_service_properties(const wchar_t *bin_path, props->version_patch= 0; args= CommandLineToArgvW(bin_path, &numargs); - - if(numargs != 3) + if(numargs == 2) + { + /* + There are rare cases where service config does not have + --defaults-filein the binary parth . There services were registered with + plain mysqld --install, the data directory is next to "bin" in this case. + Service name (second parameter) must be MySQL. + */ + if(wcscmp(args[1], L"MySQL") != 0) + goto end; + have_inifile= FALSE; + } + else if(numargs == 3) + { + have_inifile= TRUE; + } + else + { goto end; + } - if(wcsncmp(args[1], L"--defaults-file=", 16) != 0) + if(have_inifile && wcsncmp(args[1], L"--defaults-file=", 16) != 0) goto end; GetFullPathNameW(args[0], MAX_PATH, mysqld_path, &file_part); @@ -106,21 +124,66 @@ int get_mysql_service_properties(const wchar_t *bin_path, } wcstombs(props->mysqld_exe, mysqld_path, MAX_PATH); - wcstombs(props->inifile, args[1]+16, MAX_PATH); - normalize_path(props->inifile, MAX_PATH); - - if (GetFileAttributes(props->inifile) == INVALID_FILE_ATTRIBUTES) - goto end; - /* If mysqld.exe exists, try to get its version from executable */ if (GetFileAttributes(props->mysqld_exe) != INVALID_FILE_ATTRIBUTES) { - get_file_version(props->mysqld_exe, &props->version_major, + get_file_version(props->mysqld_exe, &props->version_major, &props->version_minor, &props->version_patch); } + if (have_inifile) + { + /* Easy case, we have --defaults-file in service definition. */ + wcstombs(props->inifile, args[1]+16, MAX_PATH); + normalize_path(props->inifile, MAX_PATH); + if (GetFileAttributes(props->inifile) == INVALID_FILE_ATTRIBUTES) + goto end; + GetPrivateProfileString("mysqld", "datadir", NULL, props->datadir, MAX_PATH, + props->inifile); + } + else + { + /* + Hard, although a rare case, we're guessing datadir and defaults-file. + On Windows, defaults-file is traditionally install-root\my.ini + and datadir is install-root\data + */ + char install_root[MAX_PATH]; + int i; + char *p; + + /* + Get the install root(parent of bin directory where mysqld.exe) + is located. + */ + strcpy_s(install_root, MAX_PATH, props->mysqld_exe); + for (i=0; i< 2; i++) + { + p= strrchr(install_root, '\\'); + if(!p) + goto end; + *p= 0; + } + + /* Look for my.ini in the install root */ + sprintf_s(props->inifile, MAX_PATH, "%s\\my.ini", install_root); + if (GetFileAttributes(props->inifile) != INVALID_FILE_ATTRIBUTES) + { + /* Ini file found, get datadir from there */ + GetPrivateProfileString("mysqld", "datadir", NULL, props->datadir, + MAX_PATH, props->inifile); + } + else + { + /* Ini file was not found */ + props->inifile[0]= 0; + } - GetPrivateProfileString("mysqld", "datadir", NULL, props->datadir, MAX_PATH, - props->inifile); + /* Try datadir in install directory.*/ + if (props->datadir[0] == 0) + { + sprintf_s(props->datadir, MAX_PATH, "%s\\data", install_root); + } + } if (props->datadir[0]) { |