[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libguestfs] [Bug 602599] New: [RFE] A new API for custom cleanup prior to close in perl bindings



On Thu, Jun 10, 2010 at 05:34:23AM -0400, bugzilla redhat com wrote:
>
> Summary: [RFE] A new API for custom cleanup prior to close in perl bindings
> 
> https://bugzilla.redhat.com/show_bug.cgi?id=602599
> 
>            Summary: [RFE] A new API for custom cleanup prior to close in
>                     perl bindings
>            Product: Virtualization Tools
>
> If the perl bindings introduce an explicit close API, it will no
> longer be safe to rely on object destruction to call cleanup
> code. For example, if a program creates a temporary directory which
> must persist for the duration of the program but must be cleaned up
> prior to exit, the program cannot rely on a destructor to do the
> cleanup as the handle may have been closed before the destructor is
> executed.
>
> A solution to this would be to allow callbacks to be registered and
> executed immediately prior to close(). For example:
>
> $g->pre_close(sub {
>   $g->rmdir($self->{foo});
> });

Unfortunately although this looks temptingly simple, it doesn't work
for a variety of reasons.

(1) $g is captured by the closure and so prevents implicit closure.
Of course you can explicitly close the handle now, but it's still very
counter-intuitive.

(2) Even if you explicitly close the handle, the closure will still
capture $g and prevent the handle from being freed (the reasons are
this are quite subtle -- see perlcall(3) discussion of call_sv for the
full details).

(3) Whatever you do, you end up with a static array in the XS code
storing SVs which has all sorts of horrible thread safety issues.
Again, see perlcall(3) for the details.

(4) guestfs_close can be called from exit (via an atexit handler) and
it's not at all clear that the Perl interpreter won't have been shut
down by the time we try to invoke the closure, resulting in hilarity.

Since it's now possible to store user data in the Perl handle, I
suggest pursuing a Perl-based solution to all this.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-p2v converts physical machines to virtual machines.  Boot with a
live CD or over the network (PXE) and turn machines into Xen guests.
http://et.redhat.com/~rjones/virt-p2v


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]