develooper Front page | perl.perl5.porters | Postings from November 2000

Minor suggestion for Sys::Syslog

Thread Next
Sullivan N. Beck
November 13, 2000 01:45
Minor suggestion for Sys::Syslog
Message ID:
Sys::Syslog credits you first, so hopefully you're the correct person to
contact.  If not, sorry to bother you.  Also, though I am using 5.005_03,
I've checked 5.6.0, and this applies there too.

Anyway, we recently screwed up our /etc/services file (accidentally
removed several lines, including the syslog service) which obviously led
to Sys::Syslog crashing.  It took a fair bit of effort to track down to.

>From the Sys::Syslog module (in the connect subroutine):

    unless ( $sock_type ) {
        my $udp = getprotobyname('udp');
        my $syslog = getservbyname('syslog','udp');
        my $this = sockaddr_in($syslog, INADDR_ANY);
        my $that = sockaddr_in($syslog, inet_aton($host) || croak
                "Can't lookup $host");
        socket(SYSLOG,AF_INET,SOCK_DGRAM,$udp)           || croak "socket: $!";
        connect(SYSLOG,$that)                            || croak "connect: $!";

What happens is that the getservbyname call fails (since /etc/services
doesn't contain the syslog service), but the return value isn't checked,
so Sys::Syslog doesn't fail until the connect line.  If you were to trap
the return code:

        my $udp = getprotobyname('udp') || croak "Service not defined"

it would have been much easier to figure this out.  The getprotobyname
could be trapped as well.  If this error had appeared in our logs instead
of the connect: error, it would have been much easier to track.

Thanks for all your perl work.

--------------------------|  Sullivan Beck  |---------------------------          |            Senior System Programmer     |               University of Florida
PH : (352) 392-1057                |                     CISE Department
Fax: (352) 392-1220                |                            CSE 314E

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About