From b387570fe6ed46e9eb9223a1c930ac060421f7b0 Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Thu, 27 Mar 2008 15:33:06 -0400 Subject: 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 --- ipa-server/ipaserver/installutils.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ipa-server/ipaserver/installutils.py b/ipa-server/ipaserver/installutils.py index 3d09e85c5..c261e5302 100644 --- a/ipa-server/ipaserver/installutils.py +++ b/ipa-server/ipaserver/installutils.py @@ -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: -- cgit