Prevent sockets launched for IPC communication on linux from being inherited by processes launched from the GUI

Previously only the listen socket was marked as CLOEXEC, now the actual
fd used for communication is also marked as CLOEXEC
This commit is contained in:
Kovid Goyal 2014-12-19 12:52:44 +05:30
parent 288ef018df
commit d23edad6b9

View File

@ -112,6 +112,13 @@ if islinux:
self._listener._socket.shutdown(socket.SHUT_RDWR)
self._listener._socket.close()
def accept(self, *args, **kwargs):
ans = Listener.accept(self, *args, **kwargs)
fd = ans.fileno()
old_flags = fcntl.fcntl(fd, fcntl.F_GETFD)
fcntl.fcntl(fd, fcntl.F_SETFD, old_flags | fcntl.FD_CLOEXEC)
return ans
def create_listener(authkey, backlog=4):
# Use abstract named sockets on linux to avoid creating unnecessary temp files
global _name_counter