mirror of
https://github.com/webmin/webmin.git
synced 2026-08-29 01:40:39 +01:00
Add shared server section lookup
https://github.com/webmin/webmin/pull/2827#pullrequestreview-5047577760
This commit is contained in:
@@ -14,11 +14,7 @@ if (!$conf) {
|
||||
&ui_print_footer("", $text{'index_return'});
|
||||
exit;
|
||||
}
|
||||
# Prefer the main server section over generic MariaDB sections that can
|
||||
# belong to a plugin-specific include file
|
||||
($mysqld) = grep { $_->{'name'} eq 'mysqld' } @$conf;
|
||||
($mysqld) = grep { $_->{'name'} eq 'mariadbd' } @$conf if (!$mysqld);
|
||||
($mysqld) = grep { $_->{'name'} eq 'mariadb' } @$conf if (!$mysqld);
|
||||
$mysqld = &get_mysqld_config_section($conf);
|
||||
$mysqld || &error($text{'cnf_emysqld'});
|
||||
$mems = $mysqld->{'members'};
|
||||
$local = &is_mysql_local();
|
||||
|
||||
@@ -13,11 +13,7 @@ if (!$conf) {
|
||||
&ui_print_footer("", $text{'index_return'});
|
||||
exit;
|
||||
}
|
||||
# Prefer the main server section over generic MariaDB sections that can
|
||||
# belong to a plugin-specific include file
|
||||
($mysqld) = grep { $_->{'name'} eq 'mysqld' } @$conf;
|
||||
($mysqld) = grep { $_->{'name'} eq 'mariadbd' } @$conf if (!$mysqld);
|
||||
($mysqld) = grep { $_->{'name'} eq 'mariadb' } @$conf if (!$mysqld);
|
||||
$mysqld = &get_mysqld_config_section($conf);
|
||||
$mysqld || &error($text{'cnf_emysqld'});
|
||||
$mems = $mysqld->{'members'};
|
||||
|
||||
|
||||
@@ -1358,6 +1358,19 @@ if (!scalar(@mysql_config_cache)) {
|
||||
return \@mysql_config_cache;
|
||||
}
|
||||
|
||||
# get_mysqld_config_section(&config)
|
||||
# Returns the preferred server section from a parsed MySQL configuration,
|
||||
# avoiding generic MariaDB sections when a dedicated server section exists
|
||||
sub get_mysqld_config_section
|
||||
{
|
||||
my ($conf) = @_;
|
||||
foreach my $name ('mysqld', 'mariadbd', 'mariadb') {
|
||||
my ($section) = grep { $_->{'name'} eq $name } @$conf;
|
||||
return $section if ($section);
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
# parse_mysql_config(file)
|
||||
# Reads one MySQL config file
|
||||
sub parse_mysql_config
|
||||
|
||||
@@ -12,11 +12,7 @@ foreach my $l (&get_all_mysqld_files()) {
|
||||
&lock_file($l);
|
||||
}
|
||||
$conf = &get_mysql_config();
|
||||
# Prefer the main server section over generic MariaDB sections that can
|
||||
# belong to a plugin-specific include file
|
||||
($mysqld) = grep { $_->{'name'} eq 'mysqld' } @$conf;
|
||||
($mysqld) = grep { $_->{'name'} eq 'mariadbd' } @$conf if (!$mysqld);
|
||||
($mysqld) = grep { $_->{'name'} eq 'mariadb' } @$conf if (!$mysqld);
|
||||
$mysqld = &get_mysqld_config_section($conf);
|
||||
$mysqld || &error($text{'cnf_emysqld'});
|
||||
$mems = $mysqld->{'members'};
|
||||
|
||||
|
||||
@@ -11,11 +11,7 @@ foreach my $l (&get_all_mysqld_files()) {
|
||||
&lock_file($l);
|
||||
}
|
||||
$conf = &get_mysql_config();
|
||||
# Prefer the main server section over generic MariaDB sections that can
|
||||
# belong to a plugin-specific include file
|
||||
($mysqld) = grep { $_->{'name'} eq 'mysqld' } @$conf;
|
||||
($mysqld) = grep { $_->{'name'} eq 'mariadbd' } @$conf if (!$mysqld);
|
||||
($mysqld) = grep { $_->{'name'} eq 'mariadb' } @$conf if (!$mysqld);
|
||||
$mysqld = &get_mysqld_config_section($conf);
|
||||
$mysqld || &error($text{'cnf_emysqld'});
|
||||
$mems = $mysqld->{'members'};
|
||||
|
||||
|
||||
@@ -153,4 +153,21 @@ subtest 'retention maximum is variant specific' => sub {
|
||||
'the MariaDB maximum displays as 99 days');
|
||||
};
|
||||
|
||||
subtest 'preferred MySQL server configuration section' => sub {
|
||||
my $mariadb = { 'name' => 'mariadb' };
|
||||
my $mariadbd = { 'name' => 'mariadbd' };
|
||||
my $mysqld = { 'name' => 'mysqld' };
|
||||
my $client = { 'name' => 'client' };
|
||||
|
||||
is(main::get_mysqld_config_section(
|
||||
[ $mariadb, $mariadbd, $mysqld ]), $mysqld,
|
||||
'mysqld is preferred regardless of file order');
|
||||
is(main::get_mysqld_config_section([ $mariadb, $mariadbd ]), $mariadbd,
|
||||
'mariadbd is preferred when mysqld is absent');
|
||||
is(main::get_mysqld_config_section([ $client, $mariadb ]), $mariadb,
|
||||
'mariadb is used as the final server-section fallback');
|
||||
ok(!defined(main::get_mysqld_config_section([ $client ])),
|
||||
'no server section returns undef');
|
||||
};
|
||||
|
||||
done_testing();
|
||||
|
||||
Reference in New Issue
Block a user