[pve-devel] [RFC PATCH 1/1] Add run_or_get_killed utility

Wolfgang Bumiller w.bumiller at proxmox.com
Tue Jun 20 09:21:27 CEST 2017


On Tue, Jun 20, 2017 at 09:11:13AM +0200, Wolfgang Bumiller wrote:
> > +    if (!defined($child)) {
> > +	warn "fork failed: $!\n";
> 
> Why not just die? This is an actual exception after all.

Ah I see, df() does the same. It probably shouldn't but its only user
currently doesn't want it to throw.
Ideally the df() implementation could just use this function instead
in which case either df() or PVE::LXC have to just wrap an eval{} around
the call, but for a generic "run in a fork with timeout" function the
interface should properly throw when an exceptional error occurs.

> 
> > +	return $res;
> > +    }
> > +
> > +    if (!$child) {
> > +	$pipe->writer();
> > +	eval {
> > +	    $res = $sub->();
> > +	    print {$pipe} "$res";
> > +	    $pipe->close();
> > +	};
> > +	if (my $err = $@) {
> > +	    warn $err;
> > +	    POSIX::_exit(1);
> > +	}
> > +	POSIX::_exit(0);
> > +    }
> > +
> > +    $pipe->reader();
> > +
> > +    my $readvalues = sub {

One more not here: you could add:
    local $/ = undef;
here to have <$pipe> read to the end rather than just one line.

> > +	$res = (<$pipe> =~ /^(.*)$/)[0];




More information about the pve-devel mailing list