Net-Appliance-Session - Can't use Net::Appliance::Session inside a thread

Posted on Tue Jan 22 14:41:21 2008 by miky
Can't use Net::Appliance::Session inside a thread
Hello, I'm not sure it's a Net::Appliance::Session related problem but I just wanted to have your opinion. So far I'm using Net::Telnet and Net::Telnet::Cisco and threads, everything is working fine.
When I use Net::Appliance::Session launched by a thread it segfaults. I wrote this little script that reflects my problem and which is more simple that the script I use.
#!/usr/bin/perl use Net::Appliance::Session; use threads; use threads::shared; $ip='10.1.1.1'; $host='ROUTER1'; $pf='MyPTF'; $device='cisco_router'; $connexion='ssh'; $login='miky'; $pass='mypass'; $enable=''; my $num_threads : shared = 0; my $max_thread = 1; while ($num_threads >= $max_thread) { print "$num_threads thread(s) actifs: nombre de threads maximal autorise atteint\n"; sleep 2; } $num_threads++; my $thr = threads->new('net_ssh_cisco', $ip, $host, $pf, $device, $login, $pass, $enable); $thr->detach(); sleep 2; sub net_ssh_cisco { my ($ip, $host, $pf, $device, $login, $pass, $enable) = @_; my $session; eval { $session = Net::Appliance::Session->new( Host => $ip, Transport => 'SSH' ); }; if ($@) { print "$@\n"; print "$host injoignable\n"; $num_threads--; return; } print "Connexion effective\n"; eval { $session->connect(Name=>$login, Password=>$pass); }; # <<< Problem is here if ($@) { print "$@\n"; # <<< Debug message print "$host probleme de password\n"; # <<< Debug message return; } print "Logged on "; print "$host\n"; $session->close; $num_threads--; }
When I execute the script
$ ./debugthread.pl Connexion effective Failed to get first prompt at ./debugthread.pl line 58 ROUTER1 probleme de password Segmentation fault
It seems that this message comes from Net/Appliance/Session/Transport/SSH.pm
my $match; (undef, $match) = $self->waitfor($self->pb->fetch('userpass_prompt')) or $self->error('Failed to get first prompt');
When I don't use threads it works, with threads it doesn't. Do you have an idea of what happens or could you point out a direction that could help ? Thanx
Direct Responses: 6985 | Write a response