develooper Front page | perl.perl5.porters | Postings from August 2001

[ID 20010809.036] new IO::Socket::UNIX and standard socketfunctions fail differently

From:
James Mastros
Date:
August 9, 2001 22:24
Subject:
[ID 20010809.036] new IO::Socket::UNIX and standard socketfunctions fail differently
Message ID:
E15V4ht-0007j6-00@localhost
This is a bug report for perl from james@rtweb.net,
generated with the help of perlbug 1.33 running under perl v5.6.1.


-----------------------------------------------------------------
Hello, perl5-porters,
  Here's a minor problem, but one that cost me an hour to debug, and another
hour to research this bugreport.  (I'm kind of slow & rusty & this is my
first sockets programming (I'm more used to CGI)).
  The two given scripts, test.pl and test2.pl, behave differently with
respect to $!.  (test2.pl fails the way I expected from the bind(2) manpage)

test1.pl
-- CUT --
use Socket;

socket $sock, PF_UNIX, SOCK_STREAM, 0;
if (!$sock) {
  die (sprintf("socket: %s (%d)", "$!", $!+0));
}

bind $sock, sockaddr_un "/var/mail/aimail" or
  die (sprintf("bind: %s (%d)\n", "$!", $!+0));
-- CUT --

test2.pl
-- CUT --
use IO::Socket::UNIX;

$sock = new IO::Socket::UNIX (Type=>SOCK_STREAM, 
				Local => "/var/mail/aimail");
if (!$sock) {
  die (sprintf("new: %s (%d)", "$!", $!+0));
}
-- CUT --

On my system, I get the following output:
$ sudo -u perl ./test.pl
bind: Address already in use (98)
$ sudo -u aimail perl ./test2.pl
new: Bad file descriptor (9) at ./test2.pl line 6.

$ perl ./test.pl
bind: Permission denied (13)
$ perl ./test2.pl
new: Bad file descriptor (9) at ./test2.pl line 6.

I show both to show that it's not a permissions error, and furthermore
isn't a non-POSIX error thing.  

It feels to me like IO::Socket::UNIX isn't checking that socket succeded
before trying to bind, but a read of the code seems to dispell that.

BTW, I also see no good way to bind or connect a IO::Socket::UNIX object.
Doing a $sock->bind("pathname") won't work; you have to do a
$sock->bind(sockaddr_un("filename")).

	Thank you,
	-=- James Mastros

-----------------------------------------------------------------
---
Flags:
    category=library
    severity=low
---
Site configuration information for perl v5.6.1:

Configured by bod at Fri Jun 22 18:58:01 EST 2001.

Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration:
  Platform:
    osname=linux, osvers=2.4.5-ac9, archname=i386-linux
    uname='linux duende 2.4.5-ac9 #1 thu jun 21 00:52:39 est 2001 i686 unknown '
    config_args='-Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=i386-linux -Dprefix=/usr -Dprivlib=/usr/share/perl/5.6.1 -Darchlib=/usr/lib/perl/5.6.1 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.6.1 -Dsitearch=/usr/local/lib/perl/5.6.1 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Uusesfio -Dotherlibdirs=/usr/lib/perl5/5.6:/usr/lib/perl5/5.005 -Duseshrplib -Dlibperl=libperl.so.5.6.1 -Dd_dosuid -des'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
  Compiler:
    cc='cc', ccflags ='-DDEBIAN -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-DDEBIAN -fno-strict-aliasing -I/usr/local/include'
    ccversion='', gccversion='2.95.4 20010604 (Debian prerelease)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lgdbm -ldbm -ldb -ldl -lm -lc -lcrypt
    perllibs=-ldl -lm -lc -lcrypt
    libc=/lib/libc-2.2.3.so, so=so, useshrplib=true, libperl=libperl.so.5.6.1
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    

---
@INC for perl v5.6.1:
    /usr/local/lib/perl/5.6.1
    /usr/local/share/perl/5.6.1
    /usr/lib/perl5
    /usr/share/perl5
    /usr/lib/perl/5.6.1
    /usr/share/perl/5.6.1
    /usr/local/lib/site_perl
    /usr/lib/perl5/5.6
    /usr/lib/perl5/5.005
    .

---
Environment for perl v5.6.1:
    HOME=/home/theorb
    LANG=C
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/theorb/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin/:/usr/X11R6/bin:/usr/games:.
    PERL_BADLANG (unset)
    SHELL=/bin/bash




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About