App-Diskd
view release on metacpan or search on metacpan
lib/App/Diskd.pm view on Meta::CPAN
# consequence of having distinct sessions for each program area, when
# we need to have inter-session communication, we need to use POE's
# post method. An alias is also used to identify each of the sessions.
#
##
## The DiskWatcher package sets up a session to periodically run
## blkid, parse the results and store them in our Info object. Since
## blkid can sometimes hang (due to expected devices or media not
## being present), a timer is set and if the command hasn't completed
## within that timeout, the child process is killed and the child
## session garbage collected.
##
package Local::DiskWatcher;
use POE qw(Wheel::Run Filter::Line);
sub new {
lib/App/Diskd.pm view on Meta::CPAN
$heap->{delay} = $args{frequency};
$heap->{child} = undef;
$kernel->yield('start_child');
}
# start_child is responsible for running the program with a timeout
sub start_child {
my ($kernel, $heap) = @_[KERNEL, HEAP];
# Using a named timer for timeouts. Set it to undef to deactivate.
$kernel->delay(child_timeout => $heap->{timeout});
$heap->{child} = POE::Wheel::Run->new(
Program => [$heap->{program}],
StdioFilter => POE::Filter::Line->new(),
StderrFilter => POE::Filter::Line->new(),
StdoutEvent => "got_child_stdout",
StderrEvent => "got_child_stderr",
CloseEvent => "child_cleanup",
);
lib/App/Diskd.pm view on Meta::CPAN
# For our purposes, we don't care whether the child exited by closing
# its output or throwing a SIGCHLD. Wrap the deletion of references to
# the child in if(defined()) to avoid warnings.
sub child_cleanup {
#print "DiskWatcher: child_cleanup args: ". (join ", ", @_). "\n";
my ($heap,$kernel) = @_[HEAP,KERNEL];
# Deactivate the kill timer
$kernel->delay(child_timeout => undef);
# We need to commit the new list of disks and recycle the child
# object. Both of these should only be called once, even if this
# routine is called twice.
if (defined($heap->{child})) {
my $info = $heap->{info};
$info->commit_our_disk_info;
delete $heap->{child};
( run in 1.153 second using v1.01-cache-2.11-cpan-49f99fa48dc )