summaryrefslogtreecommitdiff
path: root/sql/upgrade_conf_file.cc
diff options
context:
space:
mode:
authorVladislav Vaintroub <wlad@mariadb.com>2021-11-22 13:22:05 +0100
committerSergei Golubchik <serg@mariadb.org>2021-12-15 19:13:57 +0100
commita296c52627fc46b400d4b9e79dad1e6d8690b8cc (patch)
tree862103f7ec836207358e98ed73d8bf68164e660a /sql/upgrade_conf_file.cc
parenta4fc41b6b48a1e699343c20685a0e221002eba43 (diff)
downloadmariadb-git-a296c52627fc46b400d4b9e79dad1e6d8690b8cc.tar.gz
MDEV-26713 UTF8 support on Windows, mysql_upgrade_service preparation
- Tolerate situation, when datadir for service seems invalid/non-existing prior to upgrade. It could be that my.ini contains legacy ANSI characters for the data directory. Those can't be read correctly by mysql_upgrade_service, which uses a different ANSI codepage(UTF8) . - schedule upgrade_config_file at later stage, because once we convert it to UTF-8 (followup patch), this will render config file uselss with the older version of mariadbd.exe - Refactor upgrade_conf_file.cc, prepare for UTF-8 conversion.
Diffstat (limited to 'sql/upgrade_conf_file.cc')
-rw-r--r--sql/upgrade_conf_file.cc124
1 files changed, 88 insertions, 36 deletions
diff --git a/sql/upgrade_conf_file.cc b/sql/upgrade_conf_file.cc
index 543df7b9bdf..66d78595164 100644
--- a/sql/upgrade_conf_file.cc
+++ b/sql/upgrade_conf_file.cc
@@ -158,51 +158,103 @@ static int cmp_strings(const void* a, const void *b)
return strcmp((const char *)a, *(const char **)b);
}
-/**
- Convert file from a previous version, by removing
-*/
-int upgrade_config_file(const char *myini_path)
+
+#define MY_INI_SECTION_SIZE 32 * 1024 + 3
+
+
+int fix_section(const char *myini_path, const char *section_name,
+ bool is_server)
{
-#define MY_INI_SECTION_SIZE 32*1024 +3
+ if (!is_server)
+ return 0;
+
static char section_data[MY_INI_SECTION_SIZE];
- for (const char *section_name : { "mysqld","server","mariadb" })
+ DWORD size= GetPrivateProfileSection(section_name, section_data,
+ MY_INI_SECTION_SIZE, myini_path);
+ if (size == MY_INI_SECTION_SIZE - 2)
{
- DWORD size = GetPrivateProfileSection(section_name, section_data, MY_INI_SECTION_SIZE, myini_path);
- if (size == MY_INI_SECTION_SIZE - 2)
- {
- return -1;
- }
+ return -1;
+ }
- for (char *keyval = section_data; *keyval; keyval += strlen(keyval) + 1)
+ for (char *keyval= section_data; *keyval; keyval += strlen(keyval)+1)
+ {
+ char varname[256];
+ char *value;
+ char *key_end= strchr(keyval, '=');
+ if (!key_end)
+ key_end= keyval + strlen(keyval);
+
+ if (key_end - keyval > sizeof(varname))
+ continue;
+
+ value= key_end + 1;
+
+ // Check if variable should be removed from config.
+ // First, copy and normalize (convert dash to underscore) to variable
+ // names
+ for (char *p= keyval, *q= varname;; p++, q++)
{
- char varname[256];
- char *key_end = strchr(keyval, '=');
- if (!key_end)
- key_end = keyval+ strlen(keyval);
-
- if (key_end - keyval > sizeof(varname))
- continue;
- // copy and normalize (convert dash to underscore) to variable names
- for (char *p = keyval, *q = varname;; p++,q++)
+ if (p == key_end)
{
- if (p == key_end)
- {
- *q = 0;
- break;
- }
- *q = (*p == '-') ? '_' : *p;
+ *q= 0;
+ break;
}
- const char *v = (const char *)bsearch(varname, removed_variables, sizeof(removed_variables) / sizeof(removed_variables[0]),
- sizeof(char *), cmp_strings);
+ *q= (*p == '-') ? '_' : *p;
+ }
+ const char *v= (const char *) bsearch(varname, removed_variables, sizeof(removed_variables) / sizeof(removed_variables[0]),
+ sizeof(char *), cmp_strings);
- if (v)
- {
- fprintf(stdout, "Removing variable '%s' from config file\n", varname);
- // delete variable
- *key_end = 0;
- WritePrivateProfileString(section_name, keyval, 0, myini_path);
- }
+ if (v)
+ {
+ fprintf(stdout, "Removing variable '%s' from config file\n", varname);
+ // delete variable
+ *key_end= 0;
+ WritePrivateProfileString(section_name, keyval, 0, myini_path);
}
}
return 0;
}
+
+static bool is_mariadb_section(const char *name, bool *is_server)
+{
+ if (strncmp(name, "mysql", 5)
+ && strncmp(name, "mariadb", 7)
+ && strcmp(name, "client")
+ && strcmp(name, "client-server")
+ && strcmp(name, "server"))
+ {
+ return false;
+ }
+
+ for (const char *section_name : {"mysqld", "server", "mariadb"})
+ if (*is_server= !strcmp(section_name, name))
+ break;
+
+ return *is_server;
+}
+
+
+/**
+ Convert file from a previous version, by removing obsolete variables
+ Also, fix values to be UTF8, if MariaDB is running in utf8 mode
+*/
+int upgrade_config_file(const char *myini_path)
+{
+ static char all_sections[MY_INI_SECTION_SIZE];
+ int sz= GetPrivateProfileSectionNamesA(all_sections, MY_INI_SECTION_SIZE,
+ myini_path);
+ if (!sz)
+ return 0;
+ if (sz > MY_INI_SECTION_SIZE - 2)
+ {
+ fprintf(stderr, "Too many sections in config file\n");
+ return -1;
+ }
+ for (char *section= all_sections; *section; section+= strlen(section) + 1)
+ {
+ bool is_server_section;
+ if (is_mariadb_section(section, &is_server_section))
+ fix_section(myini_path, section, is_server_section);
+ }
+ return 0;
+}