]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/Tools.pm
Tools.pm: do not ignore "0" in split_list
[pve-common.git] / src / PVE / Tools.pm
index 4a8b5d9b530521af9c6a033da6ad2a4952e5bc07..accf6539da94d2b5d5b6f4539310fe5c4d526c7e 100644 (file)
@@ -640,7 +640,7 @@ sub pipe_socket_to_command  {
 }
 
 sub split_list {
-    my $listtxt = shift || '';
+    my $listtxt = shift // '';
 
     return split (/\0/, $listtxt) if $listtxt =~ m/\0/;
 
@@ -670,7 +670,7 @@ sub template_replace {
     return $tmpl if !$tmpl;
 
     my $res = '';
-    while ($tmpl =~ m/([^{]+)?({([^}]+)})?/g) {
+    while ($tmpl =~ m/([^{]+)?(\{([^}]+)\})?/g) {
        $res .= $1 if $1;
        $res .= ($data->{$3} || '-') if $2;
     }
@@ -760,7 +760,7 @@ my $keymaphash =  {
     'pl'     => ['Polish', 'pl', 'qwerty/pl.kmap.gz', 'pl', undef],
     'pt'     => ['Portuguese', 'pt', 'qwerty/pt-latin1.kmap.gz', 'pt', 'nodeadkeys'],
     'pt-br'  => ['Brazil-Portuguese', 'pt-br', 'qwerty/br-latin1.kmap.gz', 'br', 'nodeadkeys'],
-    #'ru'     => ['Russian', 'ru', 'qwerty/ru.kmap.gz', 'ru', undef], # dont know?
+    #'ru'     => ['Russian', 'ru', 'qwerty/ru.kmap.gz', 'ru', undef], # don't know?
     'si'     => ['Slovenian', 'sl', 'qwertz/slovene.kmap.gz', 'si', undef],
     'se'     => ['Swedish', 'sv', 'qwerty/se-latin1.kmap.gz', 'se', 'nodeadkeys'],
     #'th'     => [],
@@ -922,7 +922,6 @@ sub run_fork_with_timeout {
 
     # avoid leaving a zombie if the parent gets interrupted
     my $sig_received;
-    local $SIG{INT} = sub { $sig_received++; };
 
     my $child = fork();
     if (!defined($child)) {
@@ -946,11 +945,17 @@ sub run_fork_with_timeout {
        POSIX::_exit(0);
     }
 
+    local $SIG{INT} = sub { $sig_received++; };
+    local $SIG{TERM} = sub {
+       $error //= "interrupted by unexpected signal\n";
+       kill('TERM', $child);
+    };
+
     $pipe_out->reader();
 
     my $readvalues = sub {
        local $/ = undef;
-       my $child_res = decode_json(scalar<$pipe_out>);
+       my $child_res = decode_json(readline_nointr($pipe_out));
        $res = $child_res->{result};
        $error = $child_res->{error};
     };
@@ -1608,4 +1613,18 @@ sub readline_nointr {
     return $line;
 }
 
+sub get_host_arch {
+
+    my @uname = POSIX::uname();
+    my $machine = $uname[4];
+
+    if ($machine eq 'x86_64') {
+       return 'amd64';
+    } elsif ($machine eq 'aarch64') {
+       return 'arm64';
+    } else {
+       die "unsupported host architecture '$machine'\n";
+    }
+}
+
 1;