From 9bbc4e174ccf064b394b35b697c5f80c716c8191 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Mon, 9 Sep 2019 16:42:03 +0200 Subject: [PATCH] tree wide trailing whitespace cleanup generated with: # find . -name '*.pm' -exec sed -i 's/\s\+$//' {} \; Signed-off-by: Thomas Lamprecht --- src/PVE/CpuSet.pm | 10 ++--- src/PVE/Daemon.pm | 40 +++++++++---------- src/PVE/Exception.pm | 18 ++++----- src/PVE/INotify.pm | 70 ++++++++++++++++---------------- src/PVE/JSONSchema.pm | 90 +++++++++++++++++++++--------------------- src/PVE/Network.pm | 16 ++++---- src/PVE/ProcFSTools.pm | 6 +-- src/PVE/RESTHandler.pm | 30 +++++++------- src/PVE/SafeSyslog.pm | 4 +- 9 files changed, 142 insertions(+), 142 deletions(-) diff --git a/src/PVE/CpuSet.pm b/src/PVE/CpuSet.pm index 92fd18f..b7dc4f5 100644 --- a/src/PVE/CpuSet.pm +++ b/src/PVE/CpuSet.pm @@ -24,7 +24,7 @@ sub new_from_cgroup { my $set_text = PVE::Tools::file_read_firstline($filename) // ''; my $cpuset = $this->new(); - + my $members = $cpuset->{members}; my $count = 0; @@ -72,7 +72,7 @@ sub insert { my ($self, @members) = @_; my $count = 0; - + foreach my $cpu (@members) { next if $self->{members}->{$cpu}; $self->{members}->{$cpu} = 1; @@ -86,7 +86,7 @@ sub delete { my ($self, @members) = @_; my $count = 0; - + foreach my $cpu (@members) { next if !$self->{members}->{$cpu}; delete $self->{members}->{$cpu}; @@ -107,7 +107,7 @@ sub members { my ($self) = @_; return sort { $a <=> $b } keys %{$self->{members}}; -} +} sub size { my ($self) = @_; @@ -127,7 +127,7 @@ sub is_equal { foreach my $id (keys %$members2) { return 0 if !$members1->{$id}; } - + return 1; } diff --git a/src/PVE/Daemon.pm b/src/PVE/Daemon.pm index e3e43d9..64f8126 100644 --- a/src/PVE/Daemon.pm +++ b/src/PVE/Daemon.pm @@ -13,7 +13,7 @@ package PVE::Daemon; # * allow to restart while workers are still runningl # (option 'leave_children_open_on_reload') # * run as different user using setuid/setgid - + use strict; use warnings; use English; @@ -64,7 +64,7 @@ sub after_fork_cleanup { for my $sig (qw(CHLD HUP INT TERM QUIT)) { $SIG{$sig} = 'DEFAULT'; # restore default handler - # AnyEvent signals only works if $SIG{XX} is + # AnyEvent signals only works if $SIG{XX} is # undefined (perl event loop) delete $SIG{$sig}; # so that we can handle events with AnyEvent } @@ -80,7 +80,7 @@ my $lockpidfile = sub { if (my $fd = $self->{env_pve_lock_fd}) { $self->{daemon_lock_fh} = IO::Handle->new_from_fd($fd, "a"); - + } else { $waittime = 5; @@ -333,7 +333,7 @@ my $server_run = sub { syslog('info' , "starting server"); } - POSIX::setsid(); + POSIX::setsid(); open STDERR, '>&STDOUT' || die "can't close STDERR\n"; @@ -377,7 +377,7 @@ my $server_run = sub { } }; - eval { + eval { if ($self->{max_workers}) { my $old_sig_chld = $SIG{CHLD}; local $SIG{CHLD} = sub { @@ -387,7 +387,7 @@ my $server_run = sub { }; # now loop forever (until we receive terminate signal) - for (;;) { + for (;;) { &$start_workers($self); sleep(5); &$terminate_old_workers($self); @@ -397,7 +397,7 @@ my $server_run = sub { } else { $self->run(); - } + } }; my $err = $@; @@ -430,7 +430,7 @@ sub new { eval { my $class = ref($this) || $this; - $self = bless { + $self = bless { name => $name, pidfile => "/var/run/${name}.pid", workers => {}, @@ -458,7 +458,7 @@ sub new { die "unknown daemon option '$opt'\n"; } } - + # untaint $self->{cmdline} = [map { /^(.*)$/ } @$cmdline]; @@ -565,7 +565,7 @@ my $read_pid = sub { return 0 if !$pid_str; return 0 if $pid_str !~ m/^(\d+)$/; # untaint - + my $pid = int($1); return $pid; @@ -579,7 +579,7 @@ my $init_ppid = sub { } else { return 0; } -}; +}; sub running { my ($self) = @_; @@ -664,7 +664,7 @@ sub register_start_command { } return undef; - }}); + }}); } my $reload_daemon = sub { @@ -673,7 +673,7 @@ my $reload_daemon = sub { if ($self->{env_restart_pve_daemon}) { $self->start(); } else { - my ($running, $pid) = $self->running(); + my ($running, $pid) = $self->running(); if (!$running) { $self->start(); } else { @@ -714,7 +714,7 @@ sub register_restart_command { } return undef; - }}); + }}); } sub register_reload_command { @@ -739,7 +739,7 @@ sub register_reload_command { &$reload_daemon($self, 1); return undef; - }}); + }}); } sub register_stop_command { @@ -760,7 +760,7 @@ sub register_stop_command { code => sub { my ($param) = @_; - + if (&$init_ppid()) { $self->stop(); } else { @@ -768,7 +768,7 @@ sub register_stop_command { } return undef; - }}); + }}); } sub register_status_command { @@ -785,7 +785,7 @@ sub register_status_command { additionalProperties => 0, properties => {}, }, - returns => { + returns => { type => 'string', enum => ['stopped', 'running'], }, @@ -808,12 +808,12 @@ sub create_reusable_socket { if (defined($sockfd = $ENV{"PVE_DAEMON_SOCKET_$port"}) && $self->{env_restart_pve_daemon}) { - die "unable to parse socket fd '$sockfd'\n" + die "unable to parse socket fd '$sockfd'\n" if $sockfd !~ m/^(\d+)$/; $sockfd = $1; # untaint $socket = IO::Socket::IP->new; - $socket->fdopen($sockfd, 'w') || + $socket->fdopen($sockfd, 'w') || die "cannot fdopen file descriptor '$sockfd' - $!\n"; $socket->fcntl(Fcntl::F_SETFD(), Fcntl::FD_CLOEXEC); diff --git a/src/PVE/Exception.pm b/src/PVE/Exception.pm index 29fd94a..fe6ecbb 100644 --- a/src/PVE/Exception.pm +++ b/src/PVE/Exception.pm @@ -6,14 +6,14 @@ package PVE::Exception; use strict; use warnings; -use Storable qw(dclone); +use Storable qw(dclone); use HTTP::Status qw(:constants); use overload '""' => sub {local $@; shift->stringify}; use overload 'cmp' => sub { my ($a, $b) = @_; - local $@; + local $@; return "$a" cmp "$b"; # compare as string }; @@ -30,7 +30,7 @@ sub new { }; foreach my $p (keys %param) { - next if defined($self->{$p}); + next if defined($self->{$p}); my $v = $param{$p}; $self->{$p} = ref($v) ? dclone($v) : $v; } @@ -41,7 +41,7 @@ sub new { sub raise { my $exc = PVE::Exception->new(@_); - + my ($pkg, $filename, $line) = caller; $exc->{filename} = $filename; @@ -56,11 +56,11 @@ sub raise_perm_exc { my $param = { code => HTTP_FORBIDDEN }; my $msg = "Permission check failed"; - + $msg .= " ($what)" if $what; my $exc = PVE::Exception->new("$msg\n", %$param); - + my ($pkg, $filename, $line) = caller; $exc->{filename} = $filename; @@ -86,7 +86,7 @@ sub raise_param_exc { $param->{usage} = $usage if $usage; my $exc = PVE::Exception->new("Parameter verification failed.\n", %$param); - + my ($pkg, $filename, $line) = caller; $exc->{filename} = $filename; @@ -97,7 +97,7 @@ sub raise_param_exc { sub stringify { my $self = shift; - + my $msg = $self->{code} ? "$self->{code} $self->{msg}" : $self->{msg}; if ($msg !~ m/\n$/) { @@ -132,7 +132,7 @@ sub stringify { sub PROPAGATE { my ($self, $file, $line) = @_; - push @{$self->{propagate}}, [$file, $line]; + push @{$self->{propagate}}, [$file, $line]; return $self; } diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm index fd54313..6a7f110 100644 --- a/src/PVE/INotify.pm +++ b/src/PVE/INotify.pm @@ -84,15 +84,15 @@ sub ccache_info { $cp->{$k} = $v; } $ccache->{$filename} = $cp; - } + } return ($ccache->{$filename}, $filename); } } - + $filename = $ccachemap->{$filename} if defined ($ccachemap->{$filename}); die "file '$filename' not added :ERROR" if !defined ($ccache->{$filename}); - + return ($ccache->{$filename}, $filename); } @@ -135,7 +135,7 @@ sub write_file { if (!rename($tmpname, $realname)) { my $msg = "close (rename) atomic file '$filename' failed: $!\n"; unlink $tmpname; - die $msg; + die $msg; } my $diff; @@ -168,7 +168,7 @@ sub update_file { my $code = sub { $fd = IO::File->new ($filename, "r"); - + my $new = &$update($filename, $fd, $data, @args); if (defined($new)) { @@ -216,9 +216,9 @@ sub read_file { my $parser; my ($ccinfo, $filename) = ccache_info($fileid); - + $parser = $ccinfo->{parser}; - + my $fd; my $shadow; @@ -238,7 +238,7 @@ sub read_file { if (!$fd) { $ccinfo->{version} = undef; - $ccinfo->{data} = undef; + $ccinfo->{data} = undef; $ccinfo->{diff} = undef; return undef if !$acp; } @@ -260,7 +260,7 @@ sub read_file { $ret->{data} = $ccinfo->{data}; } $ret->{changes} = $ccinfo->{diff}; - + return $full ? $ret : $ret->{data}; } @@ -293,7 +293,7 @@ sub read_file { $ret->{changes} = $ccinfo->{diff}; return $full ? $ret : $ret->{data}; -} +} sub parse_ccache_options { my ($ccinfo, %options) = @_; @@ -337,7 +337,7 @@ sub register_file { $ccinfo->{update} = $update; parse_ccache_options($ccinfo, %options); - + if ($options{shadow}) { $shadowfiles->{$filename} = $options{shadow}; } @@ -353,7 +353,7 @@ sub register_regex { my $uid = "$dir/$regex"; die "regular expression '$uid' already added :ERROR" if defined ($ccacheregex->{$uid}); - + my $ccinfo = {}; $ccinfo->{dir} = $dir; @@ -417,7 +417,7 @@ sub inotify_init { foreach my $uid (keys %$ccacheregex) { my $ccinfo = $ccacheregex->{$uid}; - $dirhash->{$ccinfo->{dir}}->{_regex} = 1; + $dirhash->{$ccinfo->{dir}}->{_regex} = 1; } $inotify_pid = $$; @@ -447,7 +447,7 @@ sub inotify_init { syslog ('err', "got 'unmount' event on '$name' - disabling inotify"); $inotify = undef; } - if ($e->IN_IGNORED) { + if ($e->IN_IGNORED) { syslog ('err', "got 'ignored' event on '$name' - disabling inotify"); $inotify = undef; } @@ -480,7 +480,7 @@ sub inotify_init { next if $dir ne $ccinfo->{dir}; my $re = $ccinfo->{regex}; if (my $fd = IO::Dir->new ($dir)) { - while (defined(my $de = $fd->read)) { + while (defined(my $de = $fd->read)) { if ($de =~ m/^$re$/) { my $fn = "$dir/$de"; $versions->{$fn}++; # init with version @@ -535,8 +535,8 @@ sub write_etc_hostname { return $hostname; } -register_file('hostname', "/etc/hostname", - \&read_etc_hostname, +register_file('hostname', "/etc/hostname", + \&read_etc_hostname, \&write_etc_hostname); sub read_etc_hosts { @@ -629,12 +629,12 @@ sub update_etc_resolv_conf { next if $line =~ m/^(search|domain|nameserver)\s+/; $data .= $line } - + return $data; } -register_file('resolvconf', "/etc/resolv.conf", - \&read_etc_resolv_conf, undef, +register_file('resolvconf', "/etc/resolv.conf", + \&read_etc_resolv_conf, undef, \&update_etc_resolv_conf); sub read_etc_timezone { @@ -664,8 +664,8 @@ sub write_etc_timezone { } -register_file('timezone', "/etc/timezone", - \&read_etc_timezone, +register_file('timezone', "/etc/timezone", + \&read_etc_timezone, \&write_etc_timezone); sub read_active_workers { @@ -673,7 +673,7 @@ sub read_active_workers { return [] if !$fh; - my $res = []; + my $res = []; while (defined (my $line = <$fh>)) { if ($line =~ m/^(\S+)\s(0|1)(\s([0-9A-Za-z]{8})(\s(\s*\S.*))?)?$/) { my $upid = $1; @@ -717,7 +717,7 @@ sub write_active_workers { PVE::Tools::safe_print($filename, $fh, $raw) if $raw; } -register_file('active', "/var/log/pve/tasks/active", +register_file('active', "/var/log/pve/tasks/active", \&read_active_workers, \&write_active_workers); @@ -735,7 +735,7 @@ my $ovs_bond_modes = { 'active-backup' => 1, 'balance-slb' => 1, 'lacp-balance-slb' => 1, - 'lacp-balance-tcp' => 1, + 'lacp-balance-tcp' => 1, }; #sub get_bond_modes { @@ -896,12 +896,12 @@ sub __read_etc_network_interfaces { } # we try to keep order inside the file - my $priority = 2; # 1 is reserved for lo + my $priority = 2; # 1 is reserved for lo SECTION: while (defined ($line = <$fh>)) { chomp ($line); next if $line =~ m/^\s*#/; - + if ($line =~ m/^\s*auto\s+(.*)$/) { my @aa = split (/\s+/, $1); @@ -1210,7 +1210,7 @@ sub __interface_to_string { } $done->{bridge_vlan_aware} = 1; $done->{bridge_vids} = 1; - + } elsif ($d->{type} eq 'bond') { $d->{slaves} =~ s/[;,\s]+/ /g; @@ -1232,9 +1232,9 @@ sub __interface_to_string { } $done->{'bond_xmit_hash_policy'} = 1; } elsif ($d->{type} eq 'vlan') { - die "$iface: wrong vlan-protocol $d->{'vlan-protocol'}\n" + die "$iface: wrong vlan-protocol $d->{'vlan-protocol'}\n" if $d->{'vlan-protocol'} && $d->{'vlan-protocol'} ne '802.1ad' && $d->{'vlan-protocol'} ne '802.1q'; - + } elsif ($d->{type} eq 'vxlan') { foreach my $k (qw(vxlan-id vxlan-svcnodeip vxlan-physdev vxlan-local-tunnelip)) { @@ -1494,7 +1494,7 @@ sub __write_etc_network_interfaces { my $d = $ifaces->{$iface}; if (my $uplinkid = $d->{'uplink-id'}) { die "iface '$iface' - uplink-id $uplinkid is only allowed on physical and linux bond interfaces\n" - if $d->{type} ne 'eth' && $d->{type} ne 'bond'; + if $d->{type} ne 'eth' && $d->{type} ne 'bond'; die "iface '$iface' - uplink-id $uplinkid is already assigned on '$uplinks->{$uplinkid}'\n" if $uplinks->{$uplinkid}; @@ -1629,7 +1629,7 @@ sub read_iscsi_initiatorname { return 'undefined'; } -register_file('initiatorname', "/etc/iscsi/initiatorname.iscsi", +register_file('initiatorname', "/etc/iscsi/initiatorname.iscsi", \&read_iscsi_initiatorname); sub read_apt_auth { @@ -1641,7 +1641,7 @@ sub read_apt_auth { $raw =~ s/^\s+//; - + my @tokens = split(/\s+/, $raw); my $data = {}; @@ -1682,7 +1682,7 @@ sub write_apt_auth { my $raw = &$format_apt_auth_data($data); die "write failed: $!" unless print $fh "$raw\n"; - + return $data; } @@ -1698,7 +1698,7 @@ sub update_apt_auth { return &$format_apt_auth_data($orig); } -register_file('apt-auth', "/etc/apt/auth.conf", +register_file('apt-auth', "/etc/apt/auth.conf", \&read_apt_auth, \&write_apt_auth, \&update_apt_auth, perm => 0640); diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm index 58e60d8..db38d44 100644 --- a/src/PVE/JSONSchema.pm +++ b/src/PVE/JSONSchema.pm @@ -16,11 +16,11 @@ use Data::Dumper; use base 'Exporter'; our @EXPORT_OK = qw( -register_standard_option +register_standard_option get_standard_option ); -# Note: This class implements something similar to JSON schema, but it is not 100% complete. +# Note: This class implements something similar to JSON schema, but it is not 100% complete. # see: http://tools.ietf.org/html/draft-zyp-json-schema-02 # see: http://json-schema.org/ @@ -30,7 +30,7 @@ my $standard_options = {}; sub register_standard_option { my ($name, $schema) = @_; - die "standard option '$name' already registered\n" + die "standard option '$name' already registered\n" if $standard_options->{$name}; $standard_options->{$name} = $schema; @@ -77,7 +77,7 @@ register_standard_option('pve-iface', { register_standard_option('pve-storage-id', { description => "The storage identifier.", type => 'string', format => 'pve-storage-id', -}); +}); register_standard_option('pve-config-digest', { description => 'Prevent changes if current configuration file has different SHA1 digest. This can be used to prevent concurrent modifications.', @@ -124,7 +124,7 @@ my $format_list = {}; sub register_format { my ($format, $code) = @_; - die "JSON schema format '$format' already registered\n" + die "JSON schema format '$format' already registered\n" if $format_list->{$format}; $format_list->{$format} = $code; @@ -168,10 +168,10 @@ sub pve_verify_urlencoded { register_format('pve-configid', \&pve_verify_configid); sub pve_verify_configid { my ($id, $noerr) = @_; - + if ($id !~ m/^[a-z][a-z0-9_]+$/i) { return undef if $noerr; - die "invalid configuration ID '$id'\n"; + die "invalid configuration ID '$id'\n"; } return $id; } @@ -403,10 +403,10 @@ sub pve_verify_dns_name { register_format('pve-iface', \&pve_verify_iface); sub pve_verify_iface { my ($id, $noerr) = @_; - + if ($id !~ m/^[a-z][a-z0-9_]{1,20}([:\.]\d+)?$/i) { return undef if $noerr; - die "invalid network interface name '$id'\n"; + die "invalid network interface name '$id'\n"; } return $id; } @@ -438,7 +438,7 @@ sub pve_verify_disk_size { register_standard_option('spice-proxy', { description => "SPICE proxy server. This can be used by the client to specify the proxy server. All nodes in a cluster runs 'spiceproxy', so it is up to the client to choose one. By default, we return the node where the VM is currently running. As reasonable setting is to use same node you use to connect to the API (This is window.location.hostname for the JS GUI).", type => 'string', format => 'address', -}); +}); register_standard_option('remote-viewer-config', { description => "Returned values can be directly passed to the 'remote-viewer' application.", @@ -537,7 +537,7 @@ sub check_format { return if $format eq 'regex'; if ($format =~ m/^(.*)-a?list$/) { - + my $code = $format_list->{$1}; die "undefined format '$format'\n" if !$code; @@ -566,7 +566,7 @@ sub check_format { return parse_property_string($code, $value, $path) if ref($code) eq 'HASH'; &$code($value); } -} +} sub parse_size { my ($value) = @_; @@ -686,7 +686,7 @@ sub add_error { my ($errors, $path, $msg) = @_; $path = '_root' if !$path; - + if ($errors->{$path}) { $errors->{$path} = join ('\n', $errors->{$path}, $msg); } else { @@ -698,7 +698,7 @@ sub is_number { my $value = shift; # see 'man perlretut' - return $value =~ /^[+-]?(\d+\.\d+|\d+\.|\.\d+|\d+)([eE][+-]?\d+)?$/; + return $value =~ /^[+-]?(\d+\.\d+|\d+\.|\.\d+|\d+)([eE][+-]?\d+)?$/; } sub is_integer { @@ -714,7 +714,7 @@ sub check_type { if (!defined($value)) { return 1 if $type eq 'null'; - die "internal error" + die "internal error" } if (my $tt = ref($type)) { @@ -722,16 +722,16 @@ sub check_type { foreach my $t (@$type) { my $tmperr = {}; check_type($path, $t, $value, $tmperr); - return 1 if !scalar(%$tmperr); + return 1 if !scalar(%$tmperr); } my $ttext = join ('|', @$type); - add_error($errors, $path, "type check ('$ttext') failed"); + add_error($errors, $path, "type check ('$ttext') failed"); return undef; } elsif ($tt eq 'HASH') { my $tmperr = {}; check_prop($value, $type, $path, $tmperr); - return 1 if !scalar(%$tmperr); - add_error($errors, $path, "type check failed"); + return 1 if !scalar(%$tmperr); + add_error($errors, $path, "type check failed"); return undef; } else { die "internal error - got reference type '$tt'"; @@ -807,7 +807,7 @@ sub check_type { } } } - } + } return undef; } @@ -843,7 +843,7 @@ sub check_object { #print "TEST: " . Dumper($value) . "\n", Dumper($requires) ; check_prop($value, $requires, $path, $errors); } elsif (!defined($value->{$requires})) { - add_error($errors, $path ? "$path.$requires" : $requires, + add_error($errors, $path ? "$path.$requires" : $requires, "missing property - '$newpath' requires this property"); } } @@ -927,7 +927,7 @@ sub check_prop { } } } - return; + return; } elsif ($schema->{properties} || $schema->{additionalProperties}) { check_object($path, defined($schema->{properties}) ? $schema->{properties} : {}, $value, $schema->{additionalProperties}, $errors); @@ -964,17 +964,17 @@ sub check_prop { return; } } - + if (is_number($value)) { if (defined (my $max = $schema->{maximum})) { - if ($value > $max) { + if ($value > $max) { add_error($errors, $path, "value must have a maximum value of $max"); return; } } if (defined (my $min = $schema->{minimum})) { - if ($value < $min) { + if ($value < $min) { add_error($errors, $path, "value must have a minimum value of $min"); return; } @@ -1014,7 +1014,7 @@ sub validate { } elsif ($schema) { check_prop($instance, $schema, '', $errors); } - + if (scalar(%$errors)) { raise $errmsg, code => HTTP_BAD_REQUEST, errors => $errors; } @@ -1079,7 +1079,7 @@ my $default_schema_noref = { optional => 1, minimum => 0, default => 0, - }, + }, maxLength => { type => "integer", description => "When the instance value is a string, this indicates maximum length of the string.", @@ -1206,7 +1206,7 @@ my $default_schema_noref = { description => "For CLI context, this defines the maximal width to print before truncating", optional => 1, }, - } + } }; my $default_schema = Storable::dclone($default_schema_noref); @@ -1249,7 +1249,7 @@ my $method_schema = { path => {}, parameters => {}, returns => {}, - } + } }, }, method => { @@ -1260,7 +1260,7 @@ my $method_schema = { }, protected => { type => 'boolean', - description => "Method needs special privileges - only pvedaemon can execute it", + description => "Method needs special privileges - only pvedaemon can execute it", optional => 1, }, download => { @@ -1289,15 +1289,15 @@ my $method_schema = { optional => 1, }, user => { - description => "A simply way to allow access for 'all' authenticated users. Value 'world' is used to allow access without credentials.", - type => 'string', + description => "A simply way to allow access for 'all' authenticated users. Value 'world' is used to allow access without credentials.", + type => 'string', enum => ['all', 'world'], optional => 1, }, check => { description => "Array of permission checks (prefix notation).", - type => 'array', - optional => 1 + type => 'array', + optional => 1 }, }, }, @@ -1345,15 +1345,15 @@ my $method_schema = { match_name => {}, match_re => {}, fragmentDelimiter => { optional => 1 } - } + } }, - }, + }, }, }; sub validate_schema { - my ($schema) = @_; + my ($schema) = @_; my $errmsg = "internal error - unable to verify schema\n"; validate($schema, $default_schema, $errmsg); @@ -1364,13 +1364,13 @@ sub validate_method_info { my $errmsg = "internal error - unable to verify method info\n"; validate($info, $method_schema, $errmsg); - + validate_schema($info->{parameters}) if $info->{parameters}; validate_schema($info->{returns}) if $info->{returns}; } # run a self test on load -# make sure we can verify the default schema +# make sure we can verify the default schema validate_schema($default_schema_noref); validate_schema($method_schema); @@ -1397,7 +1397,7 @@ sub method_get_child_link { return $found; } -# a way to parse command line parameters, using a +# a way to parse command line parameters, using a # schema to configure Getopt::Long sub get_options { my ($schema, $args, $arg_param, $fixed_param, $param_mapping_hash) = @_; @@ -1534,7 +1534,7 @@ sub get_options { } } } - } + } } foreach my $p (keys %$fixed_param) { @@ -1549,7 +1549,7 @@ sub parse_config { my ($schema, $filename, $raw) = @_; # do fast check (avoid validate_schema($schema)) - die "got strange schema" if !$schema->{type} || + die "got strange schema" if !$schema->{type} || !$schema->{properties} || $schema->{type} ne 'object'; my $cfg = {}; @@ -1562,7 +1562,7 @@ sub parse_config { if ($line =~ m/^(\S+?):\s*(.*)$/) { my $key = $1; my $value = $2; - if ($schema->{properties}->{$key} && + if ($schema->{properties}->{$key} && $schema->{properties}->{$key}->{type} eq 'boolean') { $value = parse_boolean($value) // $value; @@ -1579,7 +1579,7 @@ sub parse_config { foreach my $k (keys %$errors) { warn "parse error in '$filename' - '$k': $errors->{$k}\n"; delete $cfg->{$k}; - } + } return $cfg; } @@ -1589,7 +1589,7 @@ sub dump_config { my ($schema, $filename, $cfg) = @_; # do fast check (avoid validate_schema($schema)) - die "got strange schema" if !$schema->{type} || + die "got strange schema" if !$schema->{type} || !$schema->{properties} || $schema->{type} ne 'object'; validate($cfg, $schema, "validation error in '$filename'\n"); diff --git a/src/PVE/Network.pm b/src/PVE/Network.pm index b1564e8..cc75445 100644 --- a/src/PVE/Network.pm +++ b/src/PVE/Network.pm @@ -233,11 +233,11 @@ my $bridge_add_interface = sub { } else { system("/sbin/bridge vlan add dev $iface vid 2-4094") == 0 || die "unable to add default vlan tags to interface $iface\n" if !$trunks; - } + } if ($trunks) { my @trunks_array = split /;/, $trunks; - foreach my $trunk (@trunks_array) { + foreach my $trunk (@trunks_array) { system("/sbin/bridge vlan add dev $iface vid $trunk") == 0 || die "unable to add vlan $trunk to interface $iface\n"; } @@ -275,7 +275,7 @@ sub tap_create { my $bridgemtu = &$read_bridge_mtu($bridge); - eval { + eval { disable_ipv6($iface); PVE::Tools::run_command(['/sbin/ip', 'link', 'set', $iface, 'up', 'promisc', 'on', 'mtu', $bridgemtu]); }; @@ -348,7 +348,7 @@ my $create_firewall_bridge_ovs = sub { # set the same mtu for ovs int port PVE::Tools::run_command(['/sbin/ip', 'link', 'set', $ovsintport, 'mtu', $bridgemtu]); - + &$bridge_add_interface($fwbr, $ovsintport); }; @@ -356,7 +356,7 @@ my $cleanup_firewall_bridge = sub { my ($iface) = @_; my ($vmid, $devid) = &$parse_tap_device_name($iface, 1); - return if !defined($vmid); + return if !defined($vmid); my ($fwbr, $vethfw, $vethfwpeer, $ovsintport) = &$compute_fwbr_names($vmid, $devid); # cleanup old port config from any openvswitch bridge @@ -422,7 +422,7 @@ sub tap_unplug { iface_set_master($iface, undef); } - + &$cleanup_firewall_bridge($iface); #cleanup old port config from any openvswitch bridge eval {run_command("/usr/bin/ovs-vsctl del-port $iface", outfunc => sub {}, errfunc => sub {}) }; @@ -433,7 +433,7 @@ sub copy_bridge_config { return if $br0 eq $br1; - my $br_configs = [ 'ageing_time', 'stp_state', 'priority', 'forward_delay', + my $br_configs = [ 'ageing_time', 'stp_state', 'priority', 'forward_delay', 'hello_time', 'max_age', 'multicast_snooping', 'multicast_querier']; foreach my $sysname (@$br_configs) { @@ -451,7 +451,7 @@ sub copy_bridge_config { sub activate_bridge_vlan_slave { my ($bridgevlan, $iface, $tag) = @_; my $ifacevlan = "${iface}.$tag"; - + # create vlan on $iface is not already exist if (! -d "/sys/class/net/$ifacevlan") { system("/sbin/ip link add link $iface name $ifacevlan type vlan id $tag") == 0 || diff --git a/src/PVE/ProcFSTools.pm b/src/PVE/ProcFSTools.pm index 027aa3a..40e4063 100644 --- a/src/PVE/ProcFSTools.pm +++ b/src/PVE/ProcFSTools.pm @@ -168,9 +168,9 @@ sub check_process_running { # for processes spanned by other processes. # kill(0, pid) return succes for zombies. # So we read the status form /proc/$pid/stat instead - + my $info = read_proc_pid_stat($pid); - + return $info && (!$pstart || ($info->{starttime} eq $pstart)) && ($info->{status} ne 'Z') ? $info : undef; } @@ -200,7 +200,7 @@ sub read_meminfo { while (my $line = <$fh>) { if ($line =~ m/^(\S+):\s+(\d+)\s*kB/i) { $d->{lc ($1)} = $2 * 1024; - } + } } close($fh); diff --git a/src/PVE/RESTHandler.pm b/src/PVE/RESTHandler.pm index 75d5d2e..04b0773 100644 --- a/src/PVE/RESTHandler.pm +++ b/src/PVE/RESTHandler.pm @@ -149,7 +149,7 @@ sub api_dump_full { $data->{$k} = ref($d) ? clone($d) : $d; } } - } + } $res->{info}->{$info->{method}} = $data; }; } @@ -248,7 +248,7 @@ sub register_method { my $path_lookup = $method_path_lookup->{$self}; die "$errprefix no path" if !defined($info->{path}); - + foreach my $comp (split(/\/+/, $info->{path})) { die "$errprefix path compoment has zero length\n" if $comp eq ''; my ($name, $regex); @@ -264,7 +264,7 @@ sub register_method { } if ($regex) { - $path_lookup->{regex} = {} if !defined($path_lookup->{regex}); + $path_lookup->{regex} = {} if !defined($path_lookup->{regex}); my $old_name = $path_lookup->{regex}->{match_name}; die "$errprefix found changed regex match name\n" @@ -274,14 +274,14 @@ sub register_method { if defined($old_re) && ($old_re ne $regex); $path_lookup->{regex}->{match_name} = $name; $path_lookup->{regex}->{match_re} = $regex; - + die "$errprefix path match error - regex and fixed items\n" if defined($path_lookup->{folders}); $path_lookup = $path_lookup->{regex}; - + } else { - $path_lookup->{folders}->{$name} = {} if !defined($path_lookup->{folders}->{$name}); + $path_lookup->{folders}->{$name} = {} if !defined($path_lookup->{folders}->{$name}); die "$errprefix path match error - regex and fixed items\n" if defined($path_lookup->{regex}); @@ -290,7 +290,7 @@ sub register_method { } } - die "$errprefix duplicate method definition\n" + die "$errprefix duplicate method definition\n" if defined($path_lookup->{$method}); if ($method eq 'SUBCLASS') { @@ -321,7 +321,7 @@ sub AUTOLOAD { my ($this) = @_; # also see "man perldiag" - + my $sub = $AUTOLOAD; (my $method = $sub) =~ s/.*:://; @@ -377,7 +377,7 @@ sub map_path_to_methods { } else { die "internal error"; } - + return undef if !$path_lookup; if (my $info = $path_lookup->{SUBCLASS}) { @@ -387,7 +387,7 @@ sub map_path_to_methods { if (defined($fd)) { # we only support the empty string '' (match whole URI) - die "unsupported fragmentDelimiter '$fd'" + die "unsupported fragmentDelimiter '$fd'" if $fd ne ''; $stack = [ join ('/', @$stack) ] if scalar(@$stack) > 1; @@ -597,7 +597,7 @@ my $compute_param_mapping_hash = sub { # # $info ... method info # $prefix ... usually something like "$exename $cmd" ('pvesm add') -# $arg_param ... list of parameters we want to get as ordered arguments +# $arg_param ... list of parameters we want to get as ordered arguments # on the command line (or single parameter name for lists) # $fixed_param ... do not generate and info about those parameters # $format: @@ -698,7 +698,7 @@ sub getopt_usage { $args .= " " if $args; $args .= "--$base <$type_text>" } - } + } if ($format eq 'asciidoc') { $out .= "*${prefix}*"; @@ -748,7 +748,7 @@ sub dump_properties { my $raw = ''; $style //= 'config'; - + my $idx_param = {}; # -vlan\d+ -scsi\d+ foreach my $k (sort keys %$prop) { @@ -781,7 +781,7 @@ sub dump_properties { next if !(ref($prop_fmt) && (ref($prop_fmt) eq 'HASH')); $raw .= dump_properties($prop_fmt, $format, 'config-sub') - + } return $raw; @@ -858,7 +858,7 @@ sub cli_handler { my $ec = ref($err); die $err if !$ec || $ec ne "PVE::Exception" || !$err->is_param_exc(); - + $err->{usage} = $self->usage_str($name, $prefix, $arg_param, $fixed_param, 'short', $param_cb, $formatter_properties); die $err; diff --git a/src/PVE/SafeSyslog.pm b/src/PVE/SafeSyslog.pm index c61e97a..7d3e7a7 100644 --- a/src/PVE/SafeSyslog.pm +++ b/src/PVE/SafeSyslog.pm @@ -13,7 +13,7 @@ our $VERSION = '1.00'; our @EXPORT = qw(syslog initlog); my $log_tag = "unknown"; - + # never log to console - thats too slow, and # it corrupts the DBD database connection! @@ -24,7 +24,7 @@ sub syslog { sub initlog { my ($tag, $facility) = @_; - if ($tag) { + if ($tag) { $tag = basename($tag); $tag = encode("ascii", decode_utf8($tag)); -- 2.39.2