use Moo;
use Object::Remote;
use Object::Remote::Future;
+use Object::Remote::Connection;
use System::Introspector::Gatherer::Bridge;
use System::Introspector::Gatherer::Report;
use Module::Runtime qw( use_module );
has introspectors => (is => 'ro', required => 1);
-
-#the gatherer is the entry point on the remote host
-#where logging has not been initialized yet so
-#it must be initialized again before the probe can
-#run
-#TODO waiting to see if this really is never coming back
-#sub init_logging {
-# my ($self, $log_level, $context) = @_;
-# System::Introspector::Logger->init_logging($context);
-# return $self;
-#}
-
-sub ping {
- my ($self) = @_;
-
- log_trace { "Gatherer just got pinged" };
- return 1;
-}
-
sub gather_all {
my ($self) = @_;
my $report = System::Introspector::Gatherer::Report->new;
log_trace { "gather_all() has been invoked" };
for my $spec (@{ $self->introspectors }) {
+
my ($base, $args) = @$spec;
my $module = "System::Introspector::Probe::$base";
log_debug { "Using '$module' for this gather" };
my $module_name = use_module($module);
log_trace { "Finished loading '$module'; returned value was '$module_name'" };
- my $instance = $module_name->new($args);
+ my $instance = $module_name->new::on('-', $args);
+ #my $instance = $module_name->new($args);
log_trace { "Finished constructing '$module_name'; starting gather" };
my $probe_data = $instance->gather;
log_trace { "Gathering completed, storing data in the report for '$module_name'" };
my $args = { introspectors => $arg{introspectors} };
if (defined $host) {
my $remote = join '@', grep defined, $user, $host;
+ my $conn = Object::Remote::Connection->conn_from_spec($remote, watchdog_timeout => 10);
+ $conn->maybe::start::connect;
if (defined $sudo_user) {
- return $class->_new_bridged($remote, $sudo, $args);
+ return $class->_new_bridged($conn->maybe::start::connect, $sudo, $args);
}
else {
- return $class->_new_direct($remote, $args);
+ return $class->_new_direct($conn->maybe::start::connect, $args);
}
}
else {
if (defined $sudo_user) {
- return $class->_new_direct($sudo, $args);
+ #TODO find a better way to achieve this result
+ my $conn = Object::Remote::Connection->conn_from_spec($sudo_user, watchdog_timeout => 10);
+
+ return $class->_new_direct($conn->maybe::start::connect, $args);
}
else {
return $class->new($args);
default => sub { '/' },
);
-has enumerate_packlists => ( is => 'ro', default => sub { 0 } );
+has enumerate_packlists => ( is => 'ro', default => sub { 1 } );
sub gather {
my ($self) = @_;
log_debug { "Gathering Perl library information" };
+
+if (0) {
+ log_warn { "simulating hang" };
+
+ while(1) {
+ sleep(1)
+ };
+}
+
return transform_exceptions {
my $pipe = $self->_open_locate_libdirs_pipe;
my %libdir;
return { modules => $self->_gather_libdir_info($line) };
};
}
+
log_trace { "Completed gathering Perl library information" };
return { libdirs_perl => \%libdir };
};
log_debug { "Gathering Perl libdir info for '$libdir'" };
my $installed = ExtUtils::Installed->new(inc_override => [ $libdir ]);
-
+
foreach my $module ($installed->modules) {
my $packlist = $installed->packlist($module)->packlist_file;
Dlog_trace { "Packlist file for '$module' in '$libdir' is '$_'" } $packlist;
-
+
$modules{$module} = {};
-
+
+if (0) {
+ log_warn { "Simulating slowness" };
+ for(1 .. 20) { sleep(1) }
+}
+
if ($self->enumerate_packlists && -f $packlist) {
$modules{$module}->{packlist} = [ $installed->files($module, 'all') ];
}
log_debug { "Executing 'locate' to identify Perl 5 library directories" };
return handle_from_command sprintf
#lib/perl5 for Local::Lib and debian installed perl? - lib/perl for others?
-# q{locate --regex '^%s.*lib/perl$'}, $root;
- q{locate --regex '^%s.*lib/perl5$'}, $root;
+ q{locate --regex '^%s.*lib/perl$'}, $root;
+# q{locate --regex '^%s.*lib/perl5$'}, $root;
}
1;
my $out;
my $child_pid;
my @lines;
- #have to temporarily out the signal so we can get the return
- #value of the child process
+ #have to temporarily block out the signal so we can get the
+ #return value of the child process
local($SIG{CHLD}) = undef;
my ($err) = capture_stderr {
$child_pid = open2($out, File::Spec->devnull, $command);
open $pipe, '<', \$content;
1;
};
+
+ #just in case any children exited while the waitpid()
+ #was blocking before
+ kill('CHLD', $$);
log_trace { "Completed reading output of '$command'" };
unless ($ok) {
my $err = $@;