SineSwiper has asked for the wisdom of the Perl Monks concerning the following question:

First, lemme start off saying that it takes ENTIRELY TOO MANY modules just to get Net::SSH::Perl to work. I understand the whole crypto module deal, but it seems like it's a lot of work just to get Perl to work with a common shell protocol.

Anyway, after installing all of these modules, including ones that weren't part of the dependancy lists (since the script basically just complained that it's missing this and that), I now get this error:

`as_number' is not a Pari function name at /usr/lib/perl5/site_perl/5. +8.3/i586-linux-thread-multi/Math/Pari.pm line 1136, <GEN0> line 1.

Can't find the error on the net/newsgroups at all. According to the line, it's trying to eval something in loadPARI, but as_number is in Math::BigInt, I think. Is Net::SSH::Perl broken, or Math::Pari? How do I fix this? (I've tried different crypto protocols in the SSH->new command, but same thing.) BTW, here's the debug info for that ssh command:

rtfkb: Reading configuration data /root/.ssh/config rtfkb: Reading configuration data /etc/ssh_config rtfkb: Allocated local port 1023. rtfkb: Connecting to x.x.x.x, port 22. rtfkb: Remote protocol version 2.0, remote software version Sun_SSH_1. +0.1 rtfkb: Net::SSH::Perl Version 1.29, protocol version 2.0. rtfkb: No compat match: Sun_SSH_1.0.1. rtfkb: Connection established. rtfkb: Sent key-exchange init (KEXINIT), wait response. rtfkb: Algorithms, c->s: blowfish-cbc hmac-sha1 none rtfkb: Algorithms, s->c: blowfish-cbc hmac-sha1 none

...and then the error

2005-11-14 Retitled by jdporter, as per Monastery guidelines. Original title: 'Bug in Math::Peri'. Also, added code tags.

Replies are listed 'Best First'.
Re: Bug in Math::Pari ?
by Fletch (Bishop) on Nov 14, 2005 at 00:29 UTC

    This is the point where you bug your sysadmin that you need software X installed and then offer up quantities of beer and pizza. And consider using Expect and running the real command line ssh through it instead if the dependencies for the Perl version are too much.

      Nono, I got root on this box, so I'm installing the modules via CPAN.

        You misunderstood my point. If you're at your wits end, punt and make the call to the closest available guru (the sysadmin, a veteran C programmer, someone who's been doing *NIX since 3B2's roamed the land . . .) and get their input on the situation. Or mail the exact error message and your platform details to the module maintainer and see if they've seen it before.

        At a minimum take an hour or so break and do something completely different, then come back and take a look at the problem fresh; very often what's wrong will jump out at you within minutes of taking it back up again. If not, then seek help elsewhere.

Re: Bug in Math::Pari ?
by dragonchild (Archbishop) on Nov 14, 2005 at 02:11 UTC
    Whenever I've had to install Net::SSH, I've always broken down and installed the C library that Math::Pari is interfacing by hand. Then, I installed Math::Pari by hand. Then, I tried again. It's about the single worst module (other than possibly DBD::Oracle on a box without any Oracle installations on it) to try and install.

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Re: Bug in Math::Pari ?
by tirwhan (Abbot) on Nov 14, 2005 at 08:06 UTC

    Not really a solution for your problem (I'd take a wild guess at a version problem in some underlying module on that), but there is now a Net::SSH2 module, maybe that will work better for you.


    Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan
Re: Bug in Math::Pari ?
by hv (Prior) on Nov 16, 2005 at 12:19 UTC

    From the other comments above, it sounds like you'll need to track down the problem yourself. By the sounds of it you have full control of the box, and can mess with the installed modules safely; if not you'll want to install local copies of the modules before you do so.

    The error message is coming from Math::Pari::can:

    sub can { my ($obj, $meth) = (@_); my $f = $obj->SUPER::can($meth); return $f if defined $f; # There is no "usual" way to get the function; try loadPari() $f = eval { loadPari($meth) }; # Math/Pari.pm line 1136 return $f if defined $f; return; }

    Since that isn't dying itself, clearly some caller is dying with this eval's $@ upon getting a failure returned.

    I'd suggest the first thing you need to do is find out the full context in which that's happening, and that's easiest done by putting diagnostics in where you know the problem is occurring:

    $f = eval { loadPari($meth) }; return $f if defined $f; + if ($meth eq 'as_number') { + require Carp; + Carp::cluck("failed to find as_number"); + } return; }

    For this sort of debugging, I tend to keep the vi session open for any module I change, so that I can easily restore the integrity of the modules by (u)ndoing all edits and re-saving. An alternative approach is to copy each module to a .orig file before editing.

    Once you have the full stack trace, you can start the debugging proper.

    Hope this helps,

    Hugo

      BTW, I'm still seeing this... I'm trying to get Net::SFTP working, which is calling Net::SSH::Perl which is using Math::BigInt which is using Math::Pari. Here is the whole caller trace (caught using a $SIG{__DIE__}):
      '__ANON__ called at Math/Pari.pm line 1148', '(eval) called at Math/Pari.pm line 1148', 'can called at Math/BigInt.pm line 2559', 'objectify called at Math/BigInt.pm line 1757', 'bmod called at Math/BigInt.pm line 114', '__ANON__ called at Net/SSH/Perl/Util/SSH2MP.pm line 28', 'mp2bin called at Net/SSH/Perl/Buffer.pm line 173', '_put_mp_int_ssh2 called at Net/SSH/Perl/Buffer.pm line 138' +, 'put_mp_int called at Net/SSH/Perl/Kex.pm line 179', 'derive_key called at Net/SSH/Perl/Kex.pm line 163', 'derive_keys called at Net/SSH/Perl/Kex/DH1.pm line 76', 'exchange called at Net/SSH/Perl/Kex.pm line 100', 'exchange called at Net/SSH/Perl/SSH2.pm line 92', '_login called at Net/SSH/Perl/SSH2.pm line 69', 'login called at Net/SFTP.pm line 62', 'init called at Net/SFTP.pm line 24', 'new called at -e line 1'
      Yes, the line it is dying on is this one:
      sub can { my ($obj, $meth) = (@_); my $f = $obj->SUPER::can($meth); return $f if defined $f; # There is no "usual" way to get the function; try loadPari() $f = eval { loadPari($meth) }; # <-- THIS LINE return $f if defined $f; return; }
      So, I'm guessing it's when the loadPari function is getting called. This function must be defined in the Dynaloader (Pari.bs or Pari.so files). I know Perl ok, but when it hits this compiled stuff I don't know how to proceed. By deduction I assume it's trying to load some C-defined function that isn't present. Now, the as_number() function has been defined in the Math::BigInt since v1.22 (2001-04-05), so I think it's not likely that it's just a newly added function and I don't have the newest function... So I'm thinking I don't have another lib that these .so and .bs files need? libpari? I'll keep looking. (And BTW, you guys were unduely harsh to this guy who seems to have been doing his best to learn... "call to the closest available guru" sheesh...)

        I wonder if $SIG{__DIE__} is exactly the problem here: the line in Math::BigInt::objectify() is:

        $k->can('as_number') ? $k = $k->as_number : $k = $a[0]->new($k);

        Now, there is a precedence error here (I've reported that), but if can() returns false it shouldn't affect us, it should simply call $a[0]->new($k).

        The code from Math::Pari::can() is:

        $f = eval { loadPari($meth) }; return $f if defined $f; return;

        .. which should correctly return undef if the loadPari() fails. However if some $SIG{__DIE__} is catching the loadPari() failure, maybe we're never getting to return from the eval. Or maybe the die handler is (inappropriately) reporting the error and the code is then successfully continuing.

        I'd be tempted for starters to put a diagnostic in objectify() just after that line, to see if a) it reaches there, and b) $k has the correct value. I'd also hunt for a $SIG{__DIE__} handler, to check what exactly it is doing - generally, such handlers should almost always act only after checking they are not inside an eval. There may be a better way, but when I needed this some time ago for a logging module the code looked like this:

        $SIG{__DIE__} = sub { # propagate the die if we're under an eval (defined($^S) && !$^S) or die(@_); # now do the real stuff ... };

        .. but there may be a better way.

        Hugo

Re: Bug in Math::Pari ?
by Anonymous Monk on Nov 14, 2005 at 04:49 UTC
    First, lemme start off saying that it takes ENTIRELY TOO MANY modules just to get Net::SSH::Perl to work.
    Why don't you rewrite it?