[pve-devel] how does errfunc in run_command exactly work?

Dietmar Maurer dietmar at proxmox.com
Fri May 31 07:43:14 CEST 2013


> In RBDPlugin.pm i found this part and i was wondering how it works.
> 
>     my $parser = sub {
>          my $line = shift;
> 
>          if ($line =~
> m/^((vm|base)-(\d+)-disk-\d+)\s+(\d+)(M|G|T)\s((\S+)\/((vm|base)-\d+-
> \S+@\S+))?/)
> {
>              my ($image, $owner, $size, $unit, $parent) = ($1, $3, $4, $5, $8);
> 
>              $list->{$pool}->{$image} = {
>                  name => $image,
>                  size => $size*rbd_unittobytes()->{$unit},
>                  parent => $parent,
>                  vmid => $owner
>              };
>          }
>      };
> 
>      eval {
>          run_command($cmd, errmsg => "rbd error", errfunc => sub { }, outfunc
> => $parser);
>      };
>      my $err = $@;
> 
> ====>    under which circumstances does run_command die? errorcode != 0?
> 
>      die $err if $err && $err !~ m/doesn't contain rbd images/ ;
> 
> Where does this content $@ comes from? errfunc does nothing...

The important thing here is:

Parameter: errmsg => "rbd error"

This records the last string from 'stderr', and use that string for the exception if errorcode != 0.





More information about the pve-devel mailing list