Socket problems on FreeBSD

Sorry to trouble you all but I’m really stumped on this one. Could
someone please advise on what might be behind this problem on FreeBSD?

The fundamental problem is that the new release of Interactive
Learning Environment (based on Ocelot) won’t start (fails in
TCPServer.new) but the prior release runs fine. So I wrote this
stripped down test case, which fails in the same way on FreeBSD but
runs fine on my linux dev box.

require 'socket’
ports=[80, 8080, 8000, 8085, 8090, 9000]
host="127.0.0.1"
ports.each { |port|
begin
s = TCPServer.new(host, port)
puts "success:#{port}"
rescue Exception => e
puts "failed:#{port}: #{e}"
end
}

On FreeBSD 4.1.1-STABLE (SERVER) I get this.

ruby test.rb
failed:80: Invalid argument - "bind(2)"
failed:8080: Invalid argument - "bind(2)"
failed:8000: Invalid argument - "bind(2)"
failed:8085: Invalid argument - "bind(2)"
failed:8090: Invalid argument - "bind(2)"
failed:9000: Invalid argument - “bind(2)”

On Linux I get this:

failed:80: Permission denied - "bind(2)"
failed:8080: Address already in use - "bind(2)"
failed:8000: Address already in use - "bind(2)"
success:8085
success:8090
success:9000

The first three ports are known busy on both machines but the other
three should be free on both machines.

···


Brad Cox, PhD; bcox@virtualschool.edu 703 361 4751
o For industrial age goods there were checks and credit cards.
For everything else there is http://virtualschool.edu/mybank
o Java Interactive Learning Environment http://virtualschool.edu/jile
o Java Web Application Architecture: http://virtualschool.edu/jwaa

Have you checked if you can access 127.0.0.1 on the BSD box? IIRC for
linux, the loopback interface needs to be running to respond to that
IP. Try pinging 127.0.0.1 on the command line.

···

On Sat, Jul 13, 2002 at 08:07:51AM +0900, Brad Cox wrote:

Sorry to trouble you all but I’m really stumped on this one. Could
someone please advise on what might be behind this problem on FreeBSD?

[deleted]


Alan Chen
Digikata LLC
http://digikata.com

Hmm… Not a solution but just for your information, I got following
result:

> uname -sr
FreeBSD 4.5-RELEASE
> ruby -v -rsocket -e 'TCPServer.new("127.0.0.1", 8080)' 
ruby 1.7.2 (2002-05-07) [i386-freebsd]
> ruby -v -rsocket -e 'TCPServer.new("127.0.0.1", 80)'  
ruby 1.7.2 (2002-05-07) [i386-freebsd]
-e:1:in `initialize': Permission denied - "bind(2)" (Errno::EACCES)
        from -e:1:in `new'
        from -e:1

What’s the version of your ruby?

···


kjana@dm4lab.to July 13, 2002
Never put off till tomorrow what you can do today.

Just spoke to Interland tech support. Turned out he’s learning ruby
too! He checked the machine and said its network stuff is fine. He
couldn’t explain the problem as I described it but passed it up to
the engineers. Hope to hear back tomorrow.

I could be more specific if I had full control of this machine, but
this is an Interland Freedom 400 Virtual Host (Freedom 400 means I
get root access) that is apparently shared by other users. From all I
can tell, it is exactly like a real FreeBSD host except that it lacks
real machine tools like ping and traceroute.

The puzzler is why the previous release of my ruby stuff is running
just fine but the new release fails during startup, on the basic
stuff I sent in the test case. They’re using different ports.

···

At 9:31 AM +0900 7/13/02, Alan Chen wrote:

On Sat, Jul 13, 2002 at 08:07:51AM +0900, Brad Cox wrote:

Sorry to trouble you all but I’m really stumped on this one. Could
someone please advise on what might be behind this problem on FreeBSD?

[deleted]

Have you checked if you can access 127.0.0.1 on the BSD box? IIRC for
linux, the loopback interface needs to be running to respond to that
IP. Try pinging 127.0.0.1 on the command line.


Alan Chen
Digikata LLC
http://digikata.com


Brad Cox, PhD; bcox@virtualschool.edu 703 361 4751
o For industrial age goods there were checks and credit cards.
For everything else there is http://virtualschool.edu/mybank
o Java Interactive Learning Environment http://virtualschool.edu/jile
o Java Web Application Architecture: http://virtualschool.edu/jwaa

Thanks. See below for comparables…

Hmm… Not a solution but just for your information, I got following
result:

> uname -sr
FreeBSD 4.5-RELEASE

bash-2.04$ uname -sr
FreeBSD 4.1.1-STABLE

> ruby -v -rsocket -e 'TCPServer.new("127.0.0.1", 8080)'
ruby 1.7.2 (2002-05-07) [i386-freebsd]

ruby 1.6.7 (2002-03-01) [i386-freebsd4.1.1]
-e:1:in `new’: Invalid argument - “bind(2)” (Errno::EINVAL)
from -e:1

> ruby -v -rsocket -e 'TCPServer.new("127.0.0.1", 80)'
ruby 1.7.2 (2002-05-07) [i386-freebsd]
-e:1:in `initialize': Permission denied - "bind(2)" (Errno::EACCES)
        from -e:1:in `new'
        from -e:1

bash-2.04$ ruby -v -rsocket -e ‘TCPServer.new(“127.0.0.1”, 80)’
ruby 1.6.7 (2002-03-01) [i386-freebsd4.1.1]
-e:1:in `new’: Invalid argument - “bind(2)” (Errno::EINVAL)
from -e:1

What’s the version of your ruby?

Above. Do you think upgrading ruby might help?

···

At 11:51 AM +0900 7/13/02, YANAGAWA Kazuhisa wrote:

Brad Cox, PhD; bcox@virtualschool.edu 703 361 4751
o For industrial age goods there were checks and credit cards.
For everything else there is http://virtualschool.edu/mybank
o Java Interactive Learning Environment http://virtualschool.edu/jile
o Java Web Application Architecture: http://virtualschool.edu/jwaa

Brad Cox bcox@virtualschool.edu writes:

The puzzler is why the previous release of my ruby stuff is running
just fine but the new release fails during startup, on the basic stuff
I sent in the test case. They’re using different ports.

Does it have strace or truss, so you can see exactly what parameters
are being passed to the bind call?

Dave

Though I have no idea about Interland Freedom 400, loopback addresses
might not be setup if you are in jail(8) environment.

“ps -p 1” would show whether you were in jail or not.

jail# ps -p 1
PID TT STAT TIME COMMAND

street# ps -p 1
PID TT STAT TIME COMMAND
1 ?? ILs 0:00.01 /sbin/init –

– Gotoken

···

At Sat, 13 Jul 2002 11:00:36 +0900, Brad Cox wrote:

I could be more specific if I had full control of this machine, but
this is an Interland Freedom 400 Virtual Host (Freedom 400 means I
get root access) that is apparently shared by other users. From all I
can tell, it is exactly like a real FreeBSD host except that it lacks
real machine tools like ping and traceroute.

Tried strace earlier but its not there. Never heard of truss before,
but it looks like digest (what’s that?) and socket.rb/socket.so are
missing. Bizarre; no idea why/how, nor why the previous version
worked at all.

bash-2.04$ truss ruby -v -rsocket -e ‘TCPServer.new(“127.0.0.1”, 8080)’
__sysctl(0xbfbffa3c,0x2,0x280ed808,0xbfbffa38,0x0,0x0) = 0 (0x0)
mmap(0x0,32768,0x3,0x1002,-1,0x0) = 672063488 (0x280ee000)
geteuid() = 1000 (0x3e8)
getuid() = 1000 (0x3e8)
getegid() = 1000 (0x3e8)
getgid() = 1000 (0x3e8)
open(“/var/run/ld-elf.so.hints”,0,00) = 3 (0x3)
read(0x3,0xbfbffa1c,0x80) = 128 (0x80)
lseek(3,0x80,0) = 128 (0x80)
read(0x3,0x280f2000,0x4c) = 76 (0x4c)
close(3) = 0 (0x0)
access(“/usr/lib/libcrypt.so.2”,0) = 0 (0x0)
open(“/usr/lib/libcrypt.so.2”,0,027757775224) = 3 (0x3)
fstat(3,0xbfbffa64) = 0 (0x0)
read(0x3,0xbfbfea34,0x1000) = 4096 (0x1000)
mmap(0x0,86016,0x5,0x2,3,0x0) = 672096256 (0x280f6000)
mmap(0x280f9000,4096,0x3,0x12,3,0x2000) = 672108544 (0x280f9000)
mmap(0x280fa000,69632,0x3,0x1012,-1,0x0) = 672112640 (0x280fa000)
close(3) = 0 (0x0)
access(“/usr/lib/libm.so.2”,0) = 0 (0x0)
open(“/usr/lib/libm.so.2”,0,027757775224) = 3 (0x3)
fstat(3,0xbfbffa64) = 0 (0x0)
read(0x3,0xbfbfea34,0x1000) = 4096 (0x1000)
mmap(0x0,110592,0x5,0x2,3,0x0) = 672182272 (0x2810b000)
mmap(0x28122000,16384,0x3,0x12,3,0x16000) = 672276480 (0x28122000)
close(3) = 0 (0x0)
access(“/usr/lib/libc.so.4”,0) = 0 (0x0)
open(“/usr/lib/libc.so.4”,0,027757775224) = 3 (0x3)
fstat(3,0xbfbffa64) = 0 (0x0)
read(0x3,0xbfbfea34,0x1000) = 4096 (0x1000)
mmap(0x0,610304,0x5,0x2,3,0x0) = 672292864 (0x28126000)
mmap(0x281a3000,20480,0x3,0x12,3,0x7c000) = 672804864 (0x281a3000)
mmap(0x281a8000,77824,0x3,0x1012,-1,0x0) = 672825344 (0x281a8000)
close(3) = 0 (0x0)
sigaction(SIGILL,0xbfbffabc,0xbfbffaa4) = 0 (0x0)
sigprocmask(0x1,0x0,0x280ed73c) = 0 (0x0)
sigaction(SIGILL,0xbfbffaa4,0x0) = 0 (0x0)
sigprocmask(0x1,0x280ed700,0xbfbffae4) = 0 (0x0)
sigprocmask(0x3,0x280ed710,0x0) = 0 (0x0)
readlink(“/etc/malloc.conf”,0xbfbff9f0,63) ERR#2 ‘No such file
or directory’
mmap(0x0,4096,0x3,0x1002,-1,0x0) = 672903168 (0x281bb000)
break(0x80ec000) = 0 (0x0)
break(0x80ed000) = 0 (0x0)
break(0x811e000) = 0 (0x0)
break(0x811f000) = 0 (0x0)
break(0x8120000) = 0 (0x0)
break(0x8121000) = 0 (0x0)
break(0x8122000) = 0 (0x0)
getrlimit(0x3,0xbfbffa90) = 0 (0x0)
break(0x8123000) = 0 (0x0)
break(0x8124000) = 0 (0x0)
break(0x8125000) = 0 (0x0)
break(0x8126000) = 0 (0x0)
break(0x8127000) = 0 (0x0)
break(0x8128000) = 0 (0x0)
break(0x8129000) = 0 (0x0)
break(0x812a000) = 0 (0x0)
break(0x812b000) = 0 (0x0)
break(0x812c000) = 0 (0x0)
break(0x812d000) = 0 (0x0)
break(0x812e000) = 0 (0x0)
break(0x812f000) = 0 (0x0)
break(0x8130000) = 0 (0x0)
break(0x8131000) = 0 (0x0)
break(0x8132000) = 0 (0x0)
break(0x8133000) = 0 (0x0)
break(0x8134000) = 0 (0x0)
break(0x8135000) = 0 (0x0)
break(0x8136000) = 0 (0x0)
break(0x8137000) = 0 (0x0)
break(0x8138000) = 0 (0x0)
break(0x8139000) = 0 (0x0)
break(0x813a000) = 0 (0x0)
break(0x813b000) = 0 (0x0)
sigaction(SIGINT,0xbfbffa58,0x0) = 0 (0x0)
sigaction(SIGHUP,0xbfbffa68,0x0) = 0 (0x0)
sigaction(SIGQUIT,0xbfbffa58,0x0) = 0 (0x0)
sigaction(SIGALRM,0xbfbffa68,0x0) = 0 (0x0)
sigaction(SIGUSR1,0xbfbffa58,0x0) = 0 (0x0)
sigaction(SIGUSR2,0xbfbffa68,0x0) = 0 (0x0)
sigaction(SIGBUS,0xbfbffa58,0x0) = 0 (0x0)
sigaction(SIGSEGV,0xbfbffa68,0x0) = 0 (0x0)
sigaction(SIGPIPE,0xbfbffa58,0x0) = 0 (0x0)
break(0x813c000) = 0 (0x0)
break(0x813d000) = 0 (0x0)
break(0x813e000) = 0 (0x0)
getuid() = 1000 (0x3e8)
geteuid() = 1000 (0x3e8)
getgid() = 1000 (0x3e8)
getegid() = 1000 (0x3e8)
fstat(1,0xbfbff680) = 0 (0x0)
ioctl(1,TIOCGETA,0xbfbff6b4) = 0 (0x0)
ruby 1.6.7 (2002-03-01) [i386-freebsd4.1.1]
write(1,0x8131400,44) = 44 (0x2c)
break(0x813f000) = 0 (0x0)
break(0x8140000) = 0 (0x0)
break(0x8141000) = 0 (0x0)
break(0x8142000) = 0 (0x0)
break(0x8143000) = 0 (0x0)
break(0x8144000) = 0 (0x0)
break(0x8145000) = 0 (0x0)
break(0x8146000) = 0 (0x0)
stat(“/usr/local/lib/ruby/site_ruby/1.6/digest.so”,0xbfbff7b0) ERR#2
‘No such file or directory’
stat(“/usr/local/lib/ruby/site_ruby/1.6/i386-freebsd4.1.1/digest.so”,0xbfbff7b0)
ERR#2 ‘No such file or directory’
stat(“/usr/local/lib/ruby/site_ruby/digest.so”,0xbfbff7b0) ERR#2 ‘No
such file or directory’
stat(“/usr/local/lib/ruby/1.6/digest.so”,0xbfbff7b0) ERR#2 ‘No such
file or directory’
stat(“/usr/local/lib/ruby/1.6/i386-freebsd4.1.1/digest.so”,0xbfbff7b0)
= 0 (0x0)
open(“/usr/local/lib/ruby/1.6/i386-freebsd4.1.1/digest.so”,0,0666) = 3 (0x3)
close(3) = 0 (0x0)
stat(“/usr/local/lib/ruby/site_ruby/1.6/digest.so”,0xbfbff7c0) ERR#2
‘No such file or directory’
stat(“/usr/local/lib/ruby/site_ruby/1.6/i386-freebsd4.1.1/digest.so”,0xbfbff7c0)
ERR#2 ‘No such file or directory’
stat(“/usr/local/lib/ruby/site_ruby/digest.so”,0xbfbff7c0) ERR#2 ‘No
such file or directory’
stat(“/usr/local/lib/ruby/1.6/digest.so”,0xbfbff7c0) ERR#2 ‘No such
file or directory’
stat(“/usr/local/lib/ruby/1.6/i386-freebsd4.1.1/digest.so”,0xbfbff7c0)
= 0 (0x0)
open(“/usr/local/lib/ruby/1.6/i386-freebsd4.1.1/digest.so”,0,0666) = 3 (0x3)
close(3) = 0 (0x0)
stat(“/usr/local/lib/ruby/site_ruby/1.6/digest.so”,0xbfbff7b0) ERR#2
‘No such file or directory’
stat(“/usr/local/lib/ruby/site_ruby/1.6/i386-freebsd4.1.1/digest.so”,0xbfbff7b0)
ERR#2 ‘No such file or directory’
stat(“/usr/local/lib/ruby/site_ruby/digest.so”,0xbfbff7b0) ERR#2 ‘No
such file or directory’
stat(“/usr/local/lib/ruby/1.6/digest.so”,0xbfbff7b0) ERR#2 ‘No such
file or directory’
stat(“/usr/local/lib/ruby/1.6/i386-freebsd4.1.1/digest.so”,0xbfbff7b0)
= 0 (0x0)
open(“/usr/local/lib/ruby/1.6/i386-freebsd4.1.1/digest.so”,0,0666) = 3 (0x3)
close(3) = 0 (0x0)
stat(“/usr/local/lib/ruby/site_ruby/1.6/digest.so”,0xbfbff7c0) ERR#2
‘No such file or directory’
stat(“/usr/local/lib/ruby/site_ruby/1.6/i386-freebsd4.1.1/digest.so”,0xbfbff7c0)
ERR#2 ‘No such file or directory’
stat(“/usr/local/lib/ruby/site_ruby/digest.so”,0xbfbff7c0) ERR#2 ‘No
such file or directory’
stat(“/usr/local/lib/ruby/1.6/digest.so”,0xbfbff7c0) ERR#2 ‘No such
file or directory’
stat(“/usr/local/lib/ruby/1.6/i386-freebsd4.1.1/digest.so”,0xbfbff7c0)
= 0 (0x0)
open(“/usr/local/lib/ruby/1.6/i386-freebsd4.1.1/digest.so”,0,0666) = 3 (0x3)
close(3) = 0 (0x0)
stat(“/usr/local/lib/ruby/site_ruby/1.6/socket.rb”,0xbfbff860) ERR#2
‘No such file or directory’
stat(“/usr/local/lib/ruby/site_ruby/1.6/socket.so”,0xbfbff860) ERR#2
‘No such file or directory’
stat(“/usr/local/lib/ruby/site_ruby/1.6/i386-freebsd4.1.1/socket.rb”,0xbfbff860)
ERR#2 ‘No such file or directory’
stat(“/usr/local/lib/ruby/site_ruby/1.6/i386-freebsd4.1.1/socket.so”,0xbfbff860)
ERR#2 ‘No such file or directory’
stat(“/usr/local/lib/ruby/site_ruby/socket.rb”,0xbfbff860) ERR#2 ‘No
such file or directory’
stat(“/usr/local/lib/ruby/site_ruby/socket.so”,0xbfbff860) ERR#2 ‘No
such file or directory’
stat(“/usr/local/lib/ruby/1.6/socket.rb”,0xbfbff860) ERR#2 ‘No such
file or directory’
stat(“/usr/local/lib/ruby/1.6/socket.so”,0xbfbff860) ERR#2 ‘No such
file or directory’
stat(“/usr/local/lib/ruby/1.6/i386-freebsd4.1.1/socket.rb”,0xbfbff860)
ERR#2 ‘No such file or directory’
stat(“/usr/local/lib/ruby/1.6/i386-freebsd4.1.1/socket.so”,0xbfbff860)
= 0 (0x0)
open(“/usr/local/lib/ruby/1.6/i386-freebsd4.1.1/socket.so”,0,0666) = 3 (0x3)
close(3) = 0 (0x0)
stat(“/usr/local/lib/ruby/site_ruby/1.6/socket.so”,0xbfbff800) ERR#2
‘No such file or directory’
stat(“/usr/local/lib/ruby/site_ruby/1.6/i386-freebsd4.1.1/socket.so”,0xbfbff800)
ERR#2 ‘No such file or directory’
stat(“/usr/local/lib/ruby/site_ruby/socket.so”,0xbfbff800) ERR#2 ‘No
such file or directory’
stat(“/usr/local/lib/ruby/1.6/socket.so”,0xbfbff800) ERR#2 ‘No such
file or directory’
stat(“/usr/local/lib/ruby/1.6/i386-freebsd4.1.1/socket.so”,0xbfbff800)
= 0 (0x0)
open(“/usr/local/lib/ruby/1.6/i386-freebsd4.1.1/socket.so”,0,0666) = 3 (0x3)
close(3) = 0 (0x0)
break(0x8147000) = 0 (0x0)
socket(0x2,0x1,0x6) = 3 (0x3)
setsockopt(0x3,0xffff,0x4,0xbfbff1d8,0x4) = 0 (0x0)
bind(0x3,0x8146060,0x10) ERR#22 ‘Invalid argument’
close(3) = 0 (0x0)
sigprocmask(0x3,0x80e9a60,0x0) = 0 (0x0)
-e:1:in `new’write(2,0x8144ef0,13) = 13 (0xd)
: write(2,0xbfbff228,2) = 2 (0x2)
Invalid argument - "bind(2)"write(2,0x8143100,28)
= 28 (0x1c)
(write(2,0xbfbff228,2) = 2 (0x2)
Errno::EINVALwrite(2,0x812a320,13) = 13 (0xd)
)
write(2,0xbfbff228,2) = 2 (0x2)
from -e:1
write(2,0xbfbff228,11) = 11 (0xb)
sigprocmask(0x1,0x280ed700,0xbfbff9a0) = 0 (0x0)
sigprocmask(0x3,0x280ed710,0x0) = 0 (0x0)
exit(0x1) process exit, rval = 256
bash-2.04$

···

At 12:02 PM +0900 7/13/02, Dave Thomas wrote:

Brad Cox bcox@virtualschool.edu writes:

The puzzler is why the previous release of my ruby stuff is running
just fine but the new release fails during startup, on the basic stuff
I sent in the test case. They’re using different ports.

Does it have strace or truss, so you can see exactly what parameters
are being passed to the bind call?


Brad Cox, PhD; bcox@virtualschool.edu 703 361 4751
o For industrial age goods there were checks and credit cards.
For everything else there is http://virtualschool.edu/mybank
o Java Interactive Learning Environment http://virtualschool.edu/jile
o Java Web Application Architecture: http://virtualschool.edu/jwaa

Though I have no idea about Interland Freedom 400, loopback addresses
might not be setup if you are in jail(8) environment.

“ps -p 1” would show whether you were in jail or not.

jail# ps -p 1
PID TT STAT TIME COMMAND

bash-2.04$ ps -p 1
PID TT STAT TIME COMMAND

Looks like jail is in effect. Question is, what to do about it. Not
to mention why the previous version is working fine. I’m stumped…

···

At 3:10 PM +0900 7/13/02, GOTO Kentaro wrote:

street# ps -p 1
PID TT STAT TIME COMMAND
1 ?? ILs 0:00.01 /sbin/init –

– Gotoken


Brad Cox, PhD; bcox@virtualschool.edu 703 361 4751
o For industrial age goods there were checks and credit cards.
For everything else there is http://virtualschool.edu/mybank
o Java Interactive Learning Environment http://virtualschool.edu/jile
o Java Web Application Architecture: http://virtualschool.edu/jwaa

but it looks like digest (what's that?) and socket.rb/socket.so are
missing. Bizarre; no idea why/how,

No, they are not missing

stat("/usr/local/lib/ruby/1.6/i386-freebsd4.1.1/digest.so",0xbfbff7b0)
= 0 (0x0)
open("/usr/local/lib/ruby/1.6/i386-freebsd4.1.1/digest.so",0,0666) = 3
(0x3)

[...]

stat("/usr/local/lib/ruby/1.6/i386-freebsd4.1.1/socket.so",0xbfbff860)
= 0 (0x0)
open("/usr/local/lib/ruby/1.6/i386-freebsd4.1.1/socket.so",0,0666) = 3
(0x3)

nor why the previous version worked at all.

Which version : 1.6.6 ?

Guy Decoux