Commit cad9a9b1 authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

MDEV-23098 mariadb-upgrade-service.exe does not work on WAMPServer

While trying to detect datadir, take into account that one can use
Windows service name as section name in options file, for Windows service.

The historical obscurity is being used by WAMP installations.
parent 6163af93
......@@ -116,6 +116,23 @@ BOOL exclude_service(mysqld_service_properties *props)
}
static void get_datadir_from_ini(const char *ini, char *service_name, char *datadir, size_t sz)
{
*datadir= 0;
const char *sections[]= {service_name, "mysqld", "server", "mariadb",
"mariadbd"};
for (int i= 0; i < sizeof(sections) / sizeof(sections[0]); i++)
{
if (sections[i])
{
GetPrivateProfileStringA(sections[i], "datadir", NULL, datadir, sz, ini);
if (*datadir)
return;
}
}
}
/*
Retrieve some properties from windows mysqld service binary path.
We're interested in ini file location and datadir, and also in version of
......@@ -135,6 +152,7 @@ int get_mysql_service_properties(const wchar_t *bin_path,
wchar_t **args= NULL;
int retval= 1;
BOOL have_inifile;
char service_name[MAX_PATH];
props->datadir[0]= 0;
props->inifile[0]= 0;
......@@ -148,7 +166,7 @@ int get_mysql_service_properties(const wchar_t *bin_path,
{
/*
There are rare cases where service config does not have
--defaults-filein the binary parth . There services were registered with
--defaults-file in the binary parth . There services were registered with
plain mysqld --install, the data directory is next to "bin" in this case.
*/
have_inifile= FALSE;
......@@ -162,6 +180,9 @@ int get_mysql_service_properties(const wchar_t *bin_path,
goto end;
}
/* Last parameter is the service name*/
wcstombs(service_name, args[numargs-1], MAX_PATH);
if(have_inifile && wcsncmp(args[1], L"--defaults-file=", 16) != 0)
goto end;
......@@ -193,8 +214,8 @@ int get_mysql_service_properties(const wchar_t *bin_path,
normalize_path(props->inifile, MAX_PATH);
if (GetFileAttributes(props->inifile) != INVALID_FILE_ATTRIBUTES)
{
GetPrivateProfileString("mysqld", "datadir", NULL, props->datadir, MAX_PATH,
props->inifile);
get_datadir_from_ini(props->inifile, service_name, props->datadir,
sizeof(props->datadir));
}
else
{
......@@ -243,8 +264,8 @@ int get_mysql_service_properties(const wchar_t *bin_path,
if (GetFileAttributes(props->inifile) != INVALID_FILE_ATTRIBUTES)
{
/* Ini file found, get datadir from there */
GetPrivateProfileString("mysqld", "datadir", NULL, props->datadir,
MAX_PATH, props->inifile);
get_datadir_from_ini(props->inifile, service_name, props->datadir,
sizeof(props->datadir));
}
else
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment