fix #7326: corosync config: allow whitespace in values
The corosync.conf parser split the whole file into whitespace separated tokens and always took exactly one token as value. Values containing whitespace, like a manually set cluster_name "my cluster", are accepted by corosync, but made the parser fail with "missing ':' after key". Any API call reading the corosync config then failed, for example when adding an HA resource. Parse the file line by line instead, like corosync does, and take the rest of the line after the first ':' as value. Section headers and closing brackets still need to be on their own line, which corosync requires anyway. Add a test config with whitespace in the cluster name. Signed-off-by: Michal Fox <me@dualfroz.com>
This commit is contained in:
1 parent
ad7bbf925f
commit
4298a304e1
2 files changed
+41
-15
No files matched your search
+11
-15
@@ -99,23 +99,20 @@ sub parse_conf {
|
||||
my $digest = Digest::SHA::sha1_hex(defined($raw) ? $raw : '');
|
||||
|
||||
$raw =~ s/#.*$//mg;
|
||||
$raw =~ s/\r?\n/ /g;
|
||||
$raw =~ s/\s+/ /g;
|
||||
$raw =~ s/^\s+//;
|
||||
$raw =~ s/\s*$//;
|
||||
|
||||
my @tokens = split(/\s/, $raw);
|
||||
|
||||
my $conf = { 'main' => {} };
|
||||
|
||||
my $stack = [];
|
||||
my $section = $conf->{main};
|
||||
|
||||
while (defined(my $token = shift @tokens)) {
|
||||
my $nexttok = $tokens[0];
|
||||
# like corosync itself, parse line by line, so that values may contain whitespace
|
||||
for my $line (split(/\r?\n/, $raw)) {
|
||||
$line =~ s/^\s+//;
|
||||
$line =~ s/\s+$//;
|
||||
next if $line eq '';
|
||||
|
||||
if ($nexttok && ($nexttok eq '{')) {
|
||||
shift @tokens; # skip '{'
|
||||
if ($line =~ m/^(\S+?)\s*\{$/) {
|
||||
my $token = $1;
|
||||
my $new_section = {};
|
||||
if ($conf_array_sections->{$token}) {
|
||||
$section->{$token} = [] if !defined($section->{$token});
|
||||
@@ -130,17 +127,16 @@ sub parse_conf {
|
||||
next;
|
||||
}
|
||||
|
||||
if ($token eq '}') {
|
||||
if ($line eq '}') {
|
||||
$section = pop @$stack;
|
||||
die "parse error - uncexpected '}'\n" if !$section;
|
||||
next;
|
||||
}
|
||||
|
||||
my $key = $token;
|
||||
die "missing ':' after key '$key'\n" if !($key =~ s/:$//);
|
||||
my ($key, $value) = $line =~ m/^([^\s:]+)\s*:\s*(.*)$/
|
||||
or die "parse error - unable to parse line '$line'\n";
|
||||
|
||||
die "parse error - no value for '$key'\n" if !defined($nexttok);
|
||||
my $value = shift @tokens;
|
||||
die "parse error - no value for '$key'\n" if $value eq '';
|
||||
|
||||
$section->{$key} = $value;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
logging {
|
||||
debug: off
|
||||
to_syslog: yes
|
||||
}
|
||||
|
||||
nodelist {
|
||||
node {
|
||||
name: prox1
|
||||
nodeid: 1
|
||||
quorum_votes: 1
|
||||
ring0_addr: prox1
|
||||
}
|
||||
}
|
||||
|
||||
quorum {
|
||||
provider: corosync_votequorum
|
||||
}
|
||||
|
||||
totem {
|
||||
cluster_name: cloud with spaces
|
||||
config_version: 1
|
||||
interface {
|
||||
bindnetaddr: 192.168.0.42
|
||||
ringnumber: 0
|
||||
}
|
||||
ip_version: ipv4
|
||||
secauth: on
|
||||
version: 2
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user