[29962] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1205 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 17 00:09:39 2008

Date: Wed, 16 Jan 2008 21:09:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 16 Jan 2008     Volume: 11 Number: 1205

Today's topics:
    Re: incorrect errno/perror with IO::socket->new <brandon.mayfield@att.net>
    Re: incorrect errno/perror with IO::socket->new <brandon.mayfield@att.net>
    Re: incorrect errno/perror with IO::socket->new <uri@stemsystems.com>
    Re: incorrect errno/perror with IO::socket->new <brandon.mayfield@att.net>
    Re: incorrect errno/perror with IO::socket->new <brandon.mayfield@att.net>
    Re: incorrect errno/perror with IO::socket->new <uri@stemsystems.com>
    Re: incorrect errno/perror with IO::socket->new <uri@stemsystems.com>
    Re: incorrect errno/perror with IO::socket->new <brandon.mayfield@att.net>
    Re: incorrect errno/perror with IO::socket->new <brandon.mayfield@att.net>
    Re: incorrect errno/perror with IO::socket->new <uri@stemsystems.com>
    Re: incorrect errno/perror with IO::socket->new <brandon.mayfield@att.net>
    Re: Wait for background processes to complete <ced@blv-sam-01.ca.boeing.com>
    Re: Wait for background processes to complete <cdalten@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 16 Jan 2008 15:14:01 -0800 (PST)
From: brandon <brandon.mayfield@att.net>
Subject: Re: incorrect errno/perror with IO::socket->new
Message-Id: <f4e37762-cb2c-4d7c-8796-3fe81251f471@d70g2000hsb.googlegroups.com>

On Jan 16, 3:00=A0pm, xhos...@gmail.com wrote:
> brandon <brandon.mayfi...@att.net> wrote:
> > =A0I have been having fits getting meaningful errno/perror values out of=

> > Perl from Socket->new() and I am hoping someone here might know what
> > is going on. The errno/perror values seem to work fine on my Linux
> > servers but AIX, HP, and Sun are not giving me a correct failure
> > value. I have remote servers set up so that I can get various types of
> > failures (no daemon, firewall blocking, no route, etc.) and I can test
> > all these conditions with telnet to see what the perror string should
> > be, and my Linux servers match that.
>
> After the "primary" error, IO::Socket might make more system calls
> before it returns to your code. =A0Those other system calls might set errn=
o,
> thus overwriting the previous value of $! set by the "primary" error.
> Because of this, IO::Socket tries to set $@ to be the most meaningful erro=
r
> message it can manage, considering the mishmash of system calls that are
> going on behind the scenes. =A0You should look in $@ instead of or in
> addition to $!. =A0(I'm saying this will solve the problem, only that it i=
s
> the first thing I'd try.)
>
> ...

 Thanks - I will definately try that.

>
>
>
> > =A0Also, I have also noticed similar behavior opening ports sucessfully.=

> > The above server had telnet running and I can open port 23
> > successfully but I get various inexplicable $! errors after the
> > new().
>
> After a successful system call, $! contains whatever it contained
> *before* that system call. =A0Looking in $! is meaningful only after
> an unsuccessful system call.
>

 Yes, and note from the code I did test it before and set it to '0'.

> Xho
>
> --
> --------------------http://NewsReader.Com/--------------------
> The costs of publication of this article were defrayed in part by the
> payment of page charges. This article must therefore be hereby marked
> advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate=

> this fact.



------------------------------

Date: Wed, 16 Jan 2008 15:18:15 -0800 (PST)
From: brandon <brandon.mayfield@att.net>
Subject: Re: incorrect errno/perror with IO::socket->new
Message-Id: <6df814da-cd4c-4746-ac6d-5035c5e54c9f@s19g2000prg.googlegroups.com>

On Jan 16, 3:00=A0pm, xhos...@gmail.com wrote:
> brandon <brandon.mayfi...@att.net> wrote:
> > =A0I have been having fits getting meaningful errno/perror values out of=

> > Perl from Socket->new() and I am hoping someone here might know what
> > is going on. The errno/perror values seem to work fine on my Linux
> > servers but AIX, HP, and Sun are not giving me a correct failure
> > value. I have remote servers set up so that I can get various types of
> > failures (no daemon, firewall blocking, no route, etc.) and I can test
> > all these conditions with telnet to see what the perror string should
> > be, and my Linux servers match that.
>
> After the "primary" error, IO::Socket might make more system calls
> before it returns to your code. =A0Those other system calls might set errn=
o,
> thus overwriting the previous value of $! set by the "primary" error.
> Because of this, IO::Socket tries to set $@ to be the most meaningful erro=
r
> message it can manage, considering the mishmash of system calls that are
> going on behind the scenes. =A0You should look in $@ instead of or in
> addition to $!. =A0(I'm saying this will solve the problem, only that it i=
s
> the first thing I'd try.)
>

 That results in :

# ./simple.pl
$! =3D
$! =3D
$! =3D A system call received a parameter that is not valid.
$@ =3D IO::Socket::INET: connect: A system call received a parameter
that is not valid.
   Use OS problem determination procedures to determine the
   source of the perror (errno) string :
         A system call received a parameter that is not valid.
#


------------------------------

Date: Wed, 16 Jan 2008 23:22:02 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: incorrect errno/perror with IO::socket->new
Message-Id: <x7zlv5we3p.fsf@mail.sysarch.com>

>>>>> "b" == brandon  <brandon.mayfield@att.net> writes:


  >> After a successful system call, $! contains whatever it contained
  >> *before* that system call.  Looking in $! is meaningful only after
  >> an unsuccessful system call.
  >> 

  b>  Yes, and note from the code I did test it before and set it to '0'.

but you are missing the point. if the call to IO::Socket->new doesn't
return undef, there is NO point in checking out $! or $@. they will be
meaningless and may be set to some irrelevant value. i have never had to
clear those before making any lib or system calls. i only check them if
there is an indicator of an error. checking them directly is wrong in
almost every case. they could be changed due to some internal call that
is redone or worked around and yet your call will still have succeeded.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Architecture, Development, Training, Support, Code Review  ------
-----------  Search or Offer Perl Jobs  ----- http://jobs.perl.org  ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


------------------------------

Date: Wed, 16 Jan 2008 15:27:31 -0800 (PST)
From: brandon <brandon.mayfield@att.net>
Subject: Re: incorrect errno/perror with IO::socket->new
Message-Id: <71393848-564f-45e3-a520-4b3ae5941191@d70g2000hsb.googlegroups.com>

On Jan 16, 4:22=A0pm, Uri Guttman <u...@stemsystems.com> wrote:
> >>>>> "b" =3D=3D brandon =A0<brandon.mayfi...@att.net> writes:
>
> =A0 >> After a successful system call, $! contains whatever it contained
> =A0 >> *before* that system call. =A0Looking in $! is meaningful only afte=
r
> =A0 >> an unsuccessful system call.
> =A0 >>
>
> =A0 b> =A0Yes, and note from the code I did test it before and set it to '=
0'.
>
> but you are missing the point. if the call to IO::Socket->new doesn't
> return undef, there is NO point in checking out $! or $@. they will be
> meaningless and may be set to some irrelevant value. i have never had to
> clear those before making any lib or system calls. i only check them if
> there is an indicator of an error. checking them directly is wrong in
> almost every case. they could be changed due to some internal call that
> is redone or worked around and yet your call will still have succeeded.
>

 But I do understand. The call is failing on port 10, I am not getting
a socket because there is no listening process on port 10. Some of the
platforms are working (Linux and Sun) and some are not (AIX and HP).
My code does check to see if the call to new() failed, I just threw in
the print's to see what it is set to in all cases as some additional
debug. I did not put those print's in until after I noticed that I was
getting strange perrors went the call failed as I expected it to.

> uri
>
> --
> Uri Guttman =A0------ =A0u...@stemsystems.com =A0-------- =A0http://www.sy=
sarch.com--
> ----- =A0Perl Architecture, Development, Training, Support, Code Review =
=A0------
> ----------- =A0Search or Offer Perl Jobs =A0-----http://jobs.perl.org=A0--=
-------
> --------- =A0Gourmet Hot Cocoa Mix =A0---- =A0http://bestfriendscocoa.com-=
--------



------------------------------

Date: Wed, 16 Jan 2008 15:43:56 -0800 (PST)
From: brandon <brandon.mayfield@att.net>
Subject: Re: incorrect errno/perror with IO::socket->new
Message-Id: <957a3d7a-b20f-4ab2-8fc1-a767c3467c77@k39g2000hsf.googlegroups.com>

I'll make the example even simpler :-) The only reason I'm printing
$! and $@ before the call is even made is to prove that errno IS
getting
set.

----------------------------------------------------------
#!/usr/bin/perl

use IO::Socket;
use strict;

my($server_ip, $server_port) = ("172.16.18.96", "10");
my($timeout) = 5;
my($socket);

print "\$! = $!\n";
print "\$@ = $@\n";

$socket = IO::Socket::INET->new(
        Proto    => "tcp",
        PeerAddr => $server_ip,
        PeerPort => $server_port,
        Timeout  => $timeout
);

if ( $socket ) {
        close $socket;
        print " OK : Port $server_port is OPEN\n";
        exit 1;
}

# else
#     Other error detected
print "\$! = $!\n";
print "\$@ = $@\n";
exit 0;
-------------------------------------------------------------

# uname -rvs
AIX 3 5
# perl -v

This is perl, v5.8.2 built for aix-thread-multi
(with 2 registered patches, see perl -V for more detail)

Copyright 1987-2003, Larry Wall

Perl may be copied only under the terms of either the Artistic License
or the
GNU General Public License, which may be found in the Perl 5 source
kit.

Complete documentation for Perl, including FAQ lists, should be found
on
this system using `man perl' or `perldoc perl'.  If you have access to
the
Internet, point your browser at http://www.perl.com/, the Perl Home
Page.

# ./simple.pl
$! =
$@ =
$! = A system call received a parameter that is not valid.
$@ = IO::Socket::INET: connect: A system call received a parameter
that is not valid.
#

I should have gotten : "A remote host refused an attempted connect
operation."

# telnet 172.16.18.96 10
Trying...
telnet: connect: A remote host refused an attempted connect operation.
#




------------------------------

Date: Thu, 17 Jan 2008 02:41:39 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: incorrect errno/perror with IO::socket->new
Message-Id: <x7d4s1w4v1.fsf@mail.sysarch.com>

>>>>> "b" == brandon  <brandon.mayfield@att.net> writes:

  b> On Jan 16, 4:22 pm, Uri Guttman <u...@stemsystems.com> wrote:
  >> >>>>> "b" == brandon  <brandon.mayfi...@att.net> writes:
  >> 
  >>   >> After a successful system call, $! contains whatever it contained
  >>   >> *before* that system call.  Looking in $! is meaningful only after
  >>   >> an unsuccessful system call.
  >>   >>
  >> 
  >>   b>  Yes, and note from the code I did test it before and set it to '0'.
  >> 
  >> but you are missing the point. if the call to IO::Socket->new doesn't
  >> return undef, there is NO point in checking out $! or $@. they will be
  >> meaningless and may be set to some irrelevant value. i have never had to
  >> clear those before making any lib or system calls. i only check them if
  >> there is an indicator of an error. checking them directly is wrong in
  >> almost every case. they could be changed due to some internal call that
  >> is redone or worked around and yet your call will still have succeeded.
  >> 

  b>  But I do understand. The call is failing on port 10, I am not getting
  b> a socket because there is no listening process on port 10. Some of the
  b> platforms are working (Linux and Sun) and some are not (AIX and HP).
  b> My code does check to see if the call to new() failed, I just threw in
  b> the print's to see what it is set to in all cases as some additional
  b> debug. I did not put those print's in until after I noticed that I was
  b> getting strange perrors went the call failed as I expected it to.

but you still don't get it. clearing error variables before the call or
printing them in all cases is useless. i repeat useless. it is not extra
debugging info but random noise. only if the new call FAILS do some of
the error vars have meaning. and $! will still be meaningless as you
don't know what internal system calls were made and if their failures
mean anything. so printing them at any time unless you make a direct
system call is useless. i repeat useless. just noise.

only print error values when you actually have an error. you detect
errors from io::socket::new by its return value. period. all preprinting
is useless. all error postprinting without an actuall error is useless.

do you understand me now??

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Architecture, Development, Training, Support, Code Review  ------
-----------  Search or Offer Perl Jobs  ----- http://jobs.perl.org  ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


------------------------------

Date: Thu, 17 Jan 2008 02:53:48 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: incorrect errno/perror with IO::socket->new
Message-Id: <x78x2pw4aw.fsf@mail.sysarch.com>

>>>>> "b" == brandon  <brandon.mayfield@att.net> writes:

  b> I'll make the example even simpler :-) The only reason I'm printing
  b> $! and $@ before the call is even made is to prove that errno IS
  b> getting
  b> set.

useless as you don't know what system calls were made and which ones may
have failed. 

  b> ----------------------------------------------------------
  b> #!/usr/bin/perl

  b> use IO::Socket;
  b> use strict;

  b> my($server_ip, $server_port) = ("172.16.18.96", "10");
  b> my($timeout) = 5;
  b> my($socket);

declare variables when first used. no need for the () in the scalar cases

  b> print "\$! = $!\n";
  b> print "\$@ = $@\n";

useless noise. no information

  b> $socket = IO::Socket::INET->new(

my $socket = ....

  b>         Proto    => "tcp",
  b>         PeerAddr => $server_ip,
  b>         PeerPort => $server_port,
  b>         Timeout  => $timeout
  b> );

  b> if ( $socket ) {
  b>         close $socket;
  b>         print " OK : Port $server_port is OPEN\n";
  b>         exit 1;
  b> }

  b> # else
  b> #     Other error detected
  b> print "\$! = $!\n";

useless as the module makes MANY system calls and you may not know which
one failed. $! is only useful on YOUR DIRECT system call.

  b> print "\$@ = $@\n";
  b> $! =
  b> $@ =

see, useless noise.

  b> $! = A system call received a parameter that is not valid.

useless error message.
  b> $@ = IO::Socket::INET: connect: A system call received a parameter
  b> that is not valid.
  b> #

  b> I should have gotten : "A remote host refused an attempted connect
  b> operation."

perl -MIO::Socket -e '$s = IO::Socket::INET->new( "127.0.0.1:1234"); print "$@\n" unless $s'
IO::Socket::INET: connect: Connection refused

 perl -MIO::Socket -e '$s = IO::Socket::INET->new( "172.16.18.96:1234"); print "$@\n" unless $s'
IO::Socket::INET: connect: Connection timed out


neither of those is what you expected so your expectations were
wrong. the telnet program is not IO::Socket.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Architecture, Development, Training, Support, Code Review  ------
-----------  Search or Offer Perl Jobs  ----- http://jobs.perl.org  ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


------------------------------

Date: Wed, 16 Jan 2008 18:54:05 -0800 (PST)
From: brandon <brandon.mayfield@att.net>
Subject: Re: incorrect errno/perror with IO::socket->new
Message-Id: <ae016d56-dde5-47a2-9ae2-4688a2110323@i72g2000hsd.googlegroups.com>

Just for grins I just now built perl 5.8.8 on an AIX 5.3 box :

# uname -svr
AIX 3 5
# /home/brandonm/perl-5.8.8/perl -v

This is perl, v5.8.8 built for aix

Copyright 1987-2006, Larry Wall

Perl may be copied only under the terms of either the Artistic License
or the
GNU General Public License, which may be found in the Perl 5 source
kit.

Complete documentation for Perl, including FAQ lists, should be found
on
this system using "man perl" or "perldoc perl".  If you have access to
the
Internet, point your browser at http://www.perl.org/, the Perl Home
Page.

# /home/brandonm/perl-5.8.8/perl -e 'print "@INC\n";'
/opt/lib/perl5/5.8.8/aix /opt/lib/perl5/5.8.8 /opt/lib/perl5/site_perl/
5.8.8/aix /opt/lib/perl5/site_perl/5.8.8 /opt/lib/perl5/site_perl .
# for i in `/home/brandonm/perl-5.8.8/perl -e 'print "@INC\n";'` ; do
find $i -name Socket.pm ; done
/opt/lib/perl5/5.8.8/aix/Socket.pm
/opt/lib/perl5/5.8.8/aix/IO/Socket.pm
/opt/lib/perl5/5.8.8/aix/Socket.pm
/opt/lib/perl5/5.8.8/aix/IO/Socket.pm
# /home/brandonm/perl-5.8.8/perl ./simple.pl
$! =
$@ =
$! = A system call received a parameter that is not valid.
$@ = IO::Socket::INET: connect: A system call received a parameter
that is not valid.
#

I removed the shebang line from the sample code so I would be sure to
get the new perl interpreter and modules.



------------------------------

Date: Wed, 16 Jan 2008 20:44:21 -0800 (PST)
From: brandon <brandon.mayfield@att.net>
Subject: Re: incorrect errno/perror with IO::socket->new
Message-Id: <b800733f-bdc7-444c-aa50-3505daca398c@v29g2000hsf.googlegroups.com>

On Jan 16, 7:53=A0pm, Uri Guttman <u...@stemsystems.com> wrote:
> >>>>> "b" =3D=3D brandon =A0<brandon.mayfi...@att.net> writes:
>
> =A0 b> I'll make the example even simpler :-) The only reason I'm printing=

> =A0 b> $! and $@ before the call is even made is to prove that errno IS
> =A0 b> getting
> =A0 b> set.
>
> useless as you don't know what system calls were made and which ones may
> have failed.
>
> =A0 b> ----------------------------------------------------------
> =A0 b> #!/usr/bin/perl
>
> =A0 b> use IO::Socket;
> =A0 b> use strict;
>
> =A0 b> my($server_ip, $server_port) =3D ("172.16.18.96", "10");
> =A0 b> my($timeout) =3D 5;
> =A0 b> my($socket);
>
> declare variables when first used. no need for the () in the scalar cases
>
> =A0 b> print "\$! =3D $!\n";
> =A0 b> print "\$@ =3D $@\n";
>
> useless noise. no information
>
> =A0 b> $socket =3D IO::Socket::INET->new(
>
> my $socket =3D ....
>
> =A0 b> =A0 =A0 =A0 =A0 Proto =A0 =A0=3D> "tcp",
> =A0 b> =A0 =A0 =A0 =A0 PeerAddr =3D> $server_ip,
> =A0 b> =A0 =A0 =A0 =A0 PeerPort =3D> $server_port,
> =A0 b> =A0 =A0 =A0 =A0 Timeout =A0=3D> $timeout
> =A0 b> );
>
> =A0 b> if ( $socket ) {
> =A0 b> =A0 =A0 =A0 =A0 close $socket;
> =A0 b> =A0 =A0 =A0 =A0 print " OK : Port $server_port is OPEN\n";
> =A0 b> =A0 =A0 =A0 =A0 exit 1;
> =A0 b> }
>
> =A0 b> # else
> =A0 b> # =A0 =A0 Other error detected
> =A0 b> print "\$! =3D $!\n";
>
> useless as the module makes MANY system calls and you may not know which
> one failed. $! is only useful on YOUR DIRECT system call.
>
> =A0 b> print "\$@ =3D $@\n";
> =A0 b> $! =3D
> =A0 b> $@ =3D
>
> see, useless noise.
>
> =A0 b> $! =3D A system call received a parameter that is not valid.
>
> useless error message.
> =A0 b> $@ =3D IO::Socket::INET: connect: A system call received a paramete=
r
> =A0 b> that is not valid.
> =A0 b> #
>
> =A0 b> I should have gotten : "A remote host refused an attempted connect
> =A0 b> operation."
>
> perl -MIO::Socket -e '$s =3D IO::Socket::INET->new( "127.0.0.1:1234"); pri=
nt "$@\n" unless $s'
> IO::Socket::INET: connect: Connection refused
>
> =A0perl -MIO::Socket -e '$s =3D IO::Socket::INET->new( "172.16.18.96:1234"=
); print "$@\n" unless $s'
> IO::Socket::INET: connect: Connection timed out
>
> neither of those is what you expected so your expectations were
> wrong. the telnet program is not IO::Socket.
>
> uri
>
> --
> Uri Guttman =A0------ =A0u...@stemsystems.com =A0-------- =A0http://www.sy=
sarch.com--
> ----- =A0Perl Architecture, Development, Training, Support, Code Review =
=A0------
> ----------- =A0Search or Offer Perl Jobs =A0-----http://jobs.perl.org=A0--=
-------
> --------- =A0Gourmet Hot Cocoa Mix =A0---- =A0http://bestfriendscocoa.com-=
--------

Hi Uri,

 That's very interesting - if I leave off the Timeout hash member,
then on AIX and HP I get the return values that I was expecting
depending for each particular failure I have set up on my test IP and
port numbers.

 Does that mean that Timeout is not valid for AIX and HP or only works
properly under certain conditions? It seems to me extremely strange
because if I try to open a port on a server that does not respond
(packets being dropped without any response from the network) then it
does seem to wait for "Timeout" seconds before returning a "timed out"
perror.

 And also the fact that the same script does return the expected
perror on Sun and Linux whether I use Timeout or not.

 I guess I get to hack a little more tomorrow, and you've helped me a
bunch but it still seems like something is inconsistent here.


------------------------------

Date: Thu, 17 Jan 2008 04:53:28 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: incorrect errno/perror with IO::socket->new
Message-Id: <x7sl0xuk6w.fsf@mail.sysarch.com>

>>>>> "b" == brandon  <brandon.mayfield@att.net> writes:

  b> On Jan 16, 7:53 pm, Uri Guttman <u...@stemsystems.com> wrote:
  >> 
  >> perl -MIO::Socket -e '$s = IO::Socket::INET->new( "127.0.0.1:1234"); print "$@\n" unless $s'
  >> IO::Socket::INET: connect: Connection refused
  >> 
  >>  perl -MIO::Socket -e '$s = IO::Socket::INET->new( "172.16.18.96:1234"); print "$@\n" unless $s'
  >> IO::Socket::INET: connect: Connection timed out

  b>  Does that mean that Timeout is not valid for AIX and HP or only works
  b> properly under certain conditions? It seems to me extremely strange
  b> because if I try to open a port on a server that does not respond
  b> (packets being dropped without any response from the network) then it
  b> does seem to wait for "Timeout" seconds before returning a "timed out"
  b> perror.

the timeout i got was a real failure of the connect and reported as
such. the timeout in io::socket timeout arg is NOT a part of any system
call and is controlled by some perl time thing like an alrm signal
breaking out of an eval block. you may be seeing the error from that
which is not important

  b>  And also the fact that the same script does return the expected
  b> perror on Sun and Linux whether I use Timeout or not.

the perror IS USELESS. i keep telling you that. there is so much code
executing in io::socket that you can't tell what error was generated by
what call. why do you keep caring about $!????? 

  b>  I guess I get to hack a little more tomorrow, and you've helped me a
  b> bunch but it still seems like something is inconsistent here.

no, your brane is inconsistant. $! has nothing to do with io::socket. do
you see any docs that say otherwise?? only check $@ if you get an error
and not a socket. ignore $!. period. that is all. you are wasting your
and our time with this. it is so simple and you think it is
complex. change your brane as the perl modules won't change for you.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Architecture, Development, Training, Support, Code Review  ------
-----------  Search or Offer Perl Jobs  ----- http://jobs.perl.org  ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


------------------------------

Date: Wed, 16 Jan 2008 21:04:11 -0800 (PST)
From: brandon <brandon.mayfield@att.net>
Subject: Re: incorrect errno/perror with IO::socket->new
Message-Id: <8a8197e6-fc11-4887-bc81-b0eb665bb395@l1g2000hsa.googlegroups.com>

On Jan 16, 7:41=A0pm, Uri Guttman <u...@stemsystems.com> wrote:
> >>>>> "b" =3D=3D brandon =A0<brandon.mayfi...@att.net> writes:
>
> =A0 b> On Jan 16, 4:22=A0pm, Uri Guttman <u...@stemsystems.com> wrote:
> =A0 >> >>>>> "b" =3D=3D brandon =A0<brandon.mayfi...@att.net> writes:
> =A0 >>
> =A0 >> =A0 >> After a successful system call, $! contains whatever it cont=
ained
> =A0 >> =A0 >> *before* that system call. =A0Looking in $! is meaningful on=
ly after
> =A0 >> =A0 >> an unsuccessful system call.
> =A0 >> =A0 >>
> =A0 >>
> =A0 >> =A0 b> =A0Yes, and note from the code I did test it before and set =
it to '0'.
> =A0 >>
> =A0 >> but you are missing the point. if the call to IO::Socket->new doesn=
't
> =A0 >> return undef, there is NO point in checking out $! or $@. they will=
 be
> =A0 >> meaningless and may be set to some irrelevant value. i have never h=
ad to
> =A0 >> clear those before making any lib or system calls. i only check the=
m if
> =A0 >> there is an indicator of an error. checking them directly is wrong =
in
> =A0 >> almost every case. they could be changed due to some internal call =
that
> =A0 >> is redone or worked around and yet your call will still have succee=
ded.
> =A0 >>
>
> =A0 b> =A0But I do understand. The call is failing on port 10, I am not ge=
tting
> =A0 b> a socket because there is no listening process on port 10. Some of =
the
> =A0 b> platforms are working (Linux and Sun) and some are not (AIX and HP)=
 .
> =A0 b> My code does check to see if the call to new() failed, I just threw=
 in
> =A0 b> the print's to see what it is set to in all cases as some additiona=
l
> =A0 b> debug. I did not put those print's in until after I noticed that I =
was
> =A0 b> getting strange perrors went the call failed as I expected it to.
>
> but you still don't get it. clearing error variables before the call or
> printing them in all cases is useless. i repeat useless. it is not extra
> debugging info but random noise. only if the new call FAILS do some of
> the error vars have meaning. and $! will still be meaningless as you
> don't know what internal system calls were made and if their failures
> mean anything. so printing them at any time unless you make a direct
> system call is useless. i repeat useless. just noise.
>
> only print error values when you actually have an error. you detect
> errors from io::socket::new by its return value. period. all preprinting
> is useless. all error postprinting without an actuall error is useless.
>
> do you understand me now??
>
> uri
>
> --
> Uri Guttman =A0------ =A0u...@stemsystems.com =A0-------- =A0http://www.sy=
sarch.com--
> ----- =A0Perl Architecture, Development, Training, Support, Code Review =
=A0------
> ----------- =A0Search or Offer Perl Jobs =A0-----http://jobs.perl.org=A0--=
-------
> --------- =A0Gourmet Hot Cocoa Mix =A0---- =A0http://bestfriendscocoa.com-=
--------

 I really did get you the first time :-) I was thinking that perhaps
the errno was NOT getting set in Socket->new() from it's system calls
(I am kinda just assuming that $! returns the current value of errno
or perror depending on the context), and I wanted to see if $! was
different before and after the call.

 If it was not changed from before the call it might mean nothing set
an error code during the call or it might mean there is a bug
somewhere if Perl (read IO::Socket::INET) is saving errno off
temporarily while it does some other system calls after the first
failure (for instance maybe it needs to make other system calls to
clean up).

 Or if was changed from before the call then at least I know something
in the call really did change it and it was not just that value to
begin with. This is the case I had, it was I guess 'undef' before the
call and something else after, turns out it may be valid (though if it
is it doesn't seem consistent across platforms) after all.

 That wasn't really what I was having trouble with, it was the $!
after the Socket->new(). Based on your next post I did find out some
more, so thanks very much for all your comments.


------------------------------

Date: Wed, 16 Jan 2008 16:52:01 -0800 (PST)
From: "comp.llang.perl.moderated" <ced@blv-sam-01.ca.boeing.com>
Subject: Re: Wait for background processes to complete
Message-Id: <406b145e-be76-4e9b-afda-23f2ffa009e0@e25g2000prg.googlegroups.com>

On Jan 16, 2:29 pm, pgodfrin <pgodf...@gmail.com> wrote:
> On Jan 16, 4:17 pm, xhos...@gmail.com wrote:
>
>
>
> > pgodfrin <pgodf...@gmail.com> wrote:
> > > Hi Ben,
> > > Well - it seems I have made some progress.But - I still need some
> > > advice...
>
> > > Here's my code:
>
> > > #!/usr/bin/perl
> > > use POSIX ":sys_wait_h";
> > > $SIG{CHLD} = sub { wait };  # an 'installed' signal handler
>
> > You probably don't need a signal handler.  And if you want it,
> > you should aware that that signal can be fired even when there is
> > no child ready to be waited for, leading to blocking in the wait.
> > So you would probably want to do a nonblocking waitpid instead.
>
> > > $f=0 ;
> > > while (</fausb/sample/*.txt>)
> > > {
> > >    $f += 1;
> > >    if ($pid = fork)
> > >    {
> > >    print "Fork $f pid: $pid\n" ;
> > >    print "Copying  $_ ($pid)\n";
> > >    # exec() NEVER returns...
> > >    exec("cp $_ $_.old") ;
> > >    } elsif (defined $pid)
> > >    {
> > >       print "Found child...($pid)\n" ;
> > >    } elsif ($! =~ /No more process/)
> > >    {
> > >       print "Fork returned no more processes\n";
> > >    } else
> > >    {
> > >       die "Fork error.\n";
> > >    }  # end fork
> > > }  # end while
> > > print "\n<<<<< End of exercise >>>>>\n";
>
> > ## On Linux, wait returns -1 when there are no living children to wait for.
> > 1 until -1==wait();
>
> > > exit;
>

> Thanks Xho - I've removed the signal handler, but it seems wait always
> returns -1 so - the loop is a nop? Where in the code should it go?
>

I'll pipe in here since the 'quick 'n dirty' solution
was mangled and diss'ed.

The safest action is an asynchronous wait with a
tight loop in the handler  (perldoc perlipc):

   use POSIX ":sys_wait_h";
   $SIG{CHLD} = \&REAPER;

   # now do something that forks...
   ...

   sub REAPER { 1 while waitpid(-1, WNOHANG)) > 0; }


--
Charles DeRykus


------------------------------

Date: Wed, 16 Jan 2008 18:06:25 -0800 (PST)
From: grocery_stocker <cdalten@gmail.com>
Subject: Re: Wait for background processes to complete
Message-Id: <a576022e-0daa-41b8-a27a-9140125ece5b@s12g2000prg.googlegroups.com>

On Jan 13, 10:09 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> [please trim your quotations]
>
> Quoth pgodfrin <pgodf...@gmail.com>:
>
> > On Jan 13, 9:51 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> > > Quoth pgodfrin <pgodf...@gmail.com>:
>
> > > > Here's what I want to do - run several commands in the background and
> > > > have the perl program wait for the commands to complete. Fork doesn't
> > > > do it, nor does wait nor waitpid.
>
> <snip>
>
> > > You need to either implement the behaviour you want with fork, exec and
> > > waitpid (it's a little complicated, but entirely possible) or use
> > > IPC::Run, something like
>
> > OK - would you have a good example of the fork-system-waitpid method -
> > not the same one that's in all the other posts or the camel book?
>
> It's a more efficient use of everybody's time for you to use IPC::Run,
> which has been written and tested by someone who understands these
> issues and is prepared to solve them properly and portably, than it is
> for a random Usenaut to provide you with a code snippet.
>
> However, off the top of my head, completely untested, probably not
> portable to Win32 or other non-POSIX systems, etc. etc.,
>
>     use POSIX qw/WNOHANG/;
>
>     {
>         my %kids;
>
>         $SIG{CHLD} = sub {
>             my ($pid, @died);
>             push @died, $pid while $pid = waitpid -1, WNOHANG;
>             delete @kids{@died};
>         };
>
>         sub background {
>             my (@cmd) = @_;
>
>             defined (my $pid = fork)
>                 or die "can't fork for '$cmd[0]': $!";
>
>             if ($pid) {
>                 $kids{$pid} = 1;
>                 return;
>             }
>             else {
>                 local $" = "' '";
>                 exec @cmd or die "can't exec '@cmd': $!";
>             }
>         }
>
>         sub finish {
>             waitpid $_, 0 for keys %kids;
>             %kids = ();
>         }
>     }
>
>     while (<*.txt>) {
>         print "Copying $_\n";
>         background cp => $_, "$_.old";
>     }
>
>     finish;
>
> This will break if used in conjunction with system or anything else that
> relies on SIGCHLD, and an OO person would probably say it should be
> implemented as an object. Use IPC::Run.
>
> Ben

I really don't grasp the significance of having $kids{$pid} equal 1.
Can some enlighten me o this?


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 1205
***************************************


home help back first fref pref prev next nref lref last post