diff --git a/src/PVE/Corosync.pm b/src/PVE/Corosync.pm index aef0d31..4be755a 100644 --- a/src/PVE/Corosync.pm +++ b/src/PVE/Corosync.pm @@ -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; } diff --git a/src/test/corosync_configs/cluster-name-with-spaces.conf b/src/test/corosync_configs/cluster-name-with-spaces.conf new file mode 100644 index 0000000..e13b005 --- /dev/null +++ b/src/test/corosync_configs/cluster-name-with-spaces.conf @@ -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 +} +