mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-20 03:36:25 +00:00
Also CLOEXEC the descriptor
This avoids leaking it into any child processes that the tests might launch.
This commit is contained in:
parent
be6e458770
commit
8a5e2edb91
@ -319,17 +319,21 @@ def foolscapEndpointForPortNumber(portnum):
|
|||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
from twisted.internet.interfaces import IReactorSocket
|
from twisted.internet.interfaces import IReactorSocket
|
||||||
if IReactorSocket.providedBy(reactor):
|
if IReactorSocket.providedBy(reactor):
|
||||||
|
import fcntl
|
||||||
from socket import socket, AF_INET
|
from socket import socket, AF_INET
|
||||||
from twisted.internet.endpoints import AdoptedStreamServerEndpoint
|
from twisted.internet.endpoints import AdoptedStreamServerEndpoint
|
||||||
s = socket()
|
s = socket()
|
||||||
try:
|
try:
|
||||||
s.setblocking(False)
|
|
||||||
s.bind(('', 0))
|
s.bind(('', 0))
|
||||||
portnum = s.getsockname()[1]
|
portnum = s.getsockname()[1]
|
||||||
s.listen(3)
|
s.listen(1)
|
||||||
|
fd = os.dup(s.fileno())
|
||||||
|
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
|
||||||
|
flags = flags | os.O_NONBLOCK | fcntl.FD_CLOEXEC
|
||||||
|
fcntl.fcntl(fd, fcntl.F_SETFD, flags)
|
||||||
return (
|
return (
|
||||||
portnum,
|
portnum,
|
||||||
AdoptedStreamServerEndpoint(reactor, os.dup(s.fileno()), AF_INET),
|
AdoptedStreamServerEndpoint(reactor, fd, AF_INET),
|
||||||
)
|
)
|
||||||
finally:
|
finally:
|
||||||
s.close()
|
s.close()
|
||||||
|
Loading…
Reference in New Issue
Block a user