Properly detect when ports are available.

The DS setup program uses Perl and does a similar port available test.
It seems that perl always sets FD_CLOEXEC and python does not. This is
why the port test would pass in python but fail in perl.

439024
This commit is contained in:
Rob Crittenden
2008-03-27 15:33:06 -04:00
parent 382ff1d29e
commit b387570fe6

View File

@@ -27,6 +27,7 @@ import fileinput
import sys
import time
import struct
import fcntl
from ipa import ipautil
from ipa import dnsclient
@@ -104,9 +105,8 @@ def port_available(port):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
fcntl.fcntl(s, fcntl.F_SETFD, fcntl.FD_CLOEXEC)
s.bind(('', port))
s.shutdown(0)
s.close()
except socket.error, e:
if e[0] == errno.EADDRINUSE:
@@ -115,9 +115,8 @@ def port_available(port):
if rv:
try:
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
fcntl.fcntl(s, fcntl.F_SETFD, fcntl.FD_CLOEXEC)
s.bind(('', port))
s.shutdown(0)
s.close()
except socket.error, e:
if e[0] == errno.EADDRINUSE: