]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
platform: Remove tornado.platform.auto.set_close_exec
authorBen Darnell <ben@cockroachlabs.com>
Fri, 26 Jun 2020 21:28:04 +0000 (17:28 -0400)
committerBen Darnell <ben@cockroachlabs.com>
Fri, 26 Jun 2020 21:28:04 +0000 (17:28 -0400)
This function is obsolete: Since python 3.4, file descriptors created
by python are non-inheritable by default (and in the event you create
a file descriptor another way, a standard function os.set_inheritable
is available).

The windows implementation of this function was also apparently
broken, but this went unnoticed because the default behavior on
windows is for file descriptors to be non-inheritable.

Fixes #2867

tornado/autoreload.py
tornado/netutil.py
tornado/platform/auto.py [deleted file]
tornado/platform/auto.pyi [deleted file]
tornado/platform/interface.py [deleted file]
tornado/platform/posix.py
tornado/platform/windows.py [deleted file]
tornado/process.py
tornado/tcpclient.py
tornado/test/runtests.py
tornado/test/windows_test.py [deleted file]

index af6c3d286df4af1444730eb85cc256a877cf111f..3299a3b34c5e86d747fa486afb4bf1098fc537e8 100644 (file)
@@ -158,8 +158,7 @@ def add_reload_hook(fn: Callable[[], None]) -> None:
 
     Note that for open file and socket handles it is generally
     preferable to set the ``FD_CLOEXEC`` flag (using `fcntl` or
-    ``tornado.platform.auto.set_close_exec``) instead
-    of using a reload hook to close them.
+    `os.set_inheritable`) instead of using a reload hook to close them.
     """
     _reload_hooks.append(fn)
 
index 6951b0f009763906bab3ee42b8566ea0081be9cd..ee7825826b3c59e90c9830fad089376d49d3ce74 100644 (file)
@@ -25,7 +25,6 @@ import stat
 
 from tornado.concurrent import dummy_executor, run_on_executor
 from tornado.ioloop import IOLoop
-from tornado.platform.auto import set_close_exec
 from tornado.util import Configurable, errno_from_exception
 
 from typing import List, Callable, Any, Type, Dict, Union, Tuple, Awaitable, Optional
@@ -130,7 +129,6 @@ def bind_sockets(
             if errno_from_exception(e) == errno.EAFNOSUPPORT:
                 continue
             raise
-        set_close_exec(sock.fileno())
         if os.name != "nt":
             try:
                 sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
@@ -203,7 +201,6 @@ if hasattr(socket, "AF_UNIX"):
         `bind_sockets`)
         """
         sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
-        set_close_exec(sock.fileno())
         try:
             sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
         except socket.error as e:
@@ -276,7 +273,6 @@ def add_accept_handler(
                 # but it was closed while still in the accept queue.
                 # (observed on FreeBSD).
                 continue
-            set_close_exec(connection.fileno())
             callback(connection, address)
 
     def remove_handler() -> None:
diff --git a/tornado/platform/auto.py b/tornado/platform/auto.py
deleted file mode 100644 (file)
index 4f1b6ac..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-#
-# Copyright 2011 Facebook
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-"""Implementation of platform-specific functionality.
-
-For each function or class described in `tornado.platform.interface`,
-the appropriate platform-specific implementation exists in this module.
-Most code that needs access to this functionality should do e.g.::
-
-    from tornado.platform.auto import set_close_exec
-"""
-
-import os
-
-if os.name == "nt":
-    from tornado.platform.windows import set_close_exec
-else:
-    from tornado.platform.posix import set_close_exec
-
-__all__ = ["set_close_exec"]
diff --git a/tornado/platform/auto.pyi b/tornado/platform/auto.pyi
deleted file mode 100644 (file)
index a1c9722..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-# auto.py is full of patterns mypy doesn't like, so for type checking
-# purposes we replace it with interface.py.
-
-from .interface import *
diff --git a/tornado/platform/interface.py b/tornado/platform/interface.py
deleted file mode 100644 (file)
index 11afdb1..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-#
-# Copyright 2011 Facebook
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-"""Interfaces for platform-specific functionality.
-
-This module exists primarily for documentation purposes and as base classes
-for other tornado.platform modules.  Most code should import the appropriate
-implementation from `tornado.platform.auto`.
-"""
-
-
-def set_close_exec(fd: int) -> None:
-    """Sets the close-on-exec bit (``FD_CLOEXEC``)for a file descriptor."""
-    raise NotImplementedError()
index 0ab27ca851d0c8bbec26fca0ba2fd631fa684a54..e4699a6fcd623e62d50f72975ccf8a08f1019003 100644 (file)
@@ -19,11 +19,6 @@ import fcntl
 import os
 
 
-def set_close_exec(fd: int) -> None:
-    flags = fcntl.fcntl(fd, fcntl.F_GETFD)
-    fcntl.fcntl(fd, fcntl.F_SETFD, flags | fcntl.FD_CLOEXEC)
-
-
 def _set_nonblocking(fd: int) -> None:
     flags = fcntl.fcntl(fd, fcntl.F_GETFL)
     fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK)
diff --git a/tornado/platform/windows.py b/tornado/platform/windows.py
deleted file mode 100644 (file)
index ddbde20..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-# NOTE: win32 support is currently experimental, and not recommended
-# for production use.
-
-import ctypes
-import ctypes.wintypes
-
-# See: http://msdn.microsoft.com/en-us/library/ms724935(VS.85).aspx
-SetHandleInformation = ctypes.windll.kernel32.SetHandleInformation  # type: ignore
-SetHandleInformation.argtypes = (
-    ctypes.wintypes.HANDLE,
-    ctypes.wintypes.DWORD,
-    ctypes.wintypes.DWORD,
-)
-SetHandleInformation.restype = ctypes.wintypes.BOOL
-
-HANDLE_FLAG_INHERIT = 0x00000001
-
-
-def set_close_exec(fd: int) -> None:
-    success = SetHandleInformation(fd, HANDLE_FLAG_INHERIT, 0)
-    if not success:
-        raise ctypes.WinError()  # type: ignore
index 90f6bdd0dc1944642a97b6b821da4076c49c9f09..26428feb7780d1da595d856e80934ec7f5262224 100644 (file)
@@ -34,10 +34,9 @@ from tornado.concurrent import (
 from tornado import ioloop
 from tornado.iostream import PipeIOStream
 from tornado.log import gen_log
-from tornado.platform.auto import set_close_exec
 
 import typing
-from typing import Tuple, Optional, Any, Callable
+from typing import Optional, Any, Callable
 
 if typing.TYPE_CHECKING:
     from typing import List  # noqa: F401
@@ -77,13 +76,6 @@ def _reseed_random() -> None:
     random.seed(seed)
 
 
-def _pipe_cloexec() -> Tuple[int, int]:
-    r, w = os.pipe()
-    set_close_exec(r)
-    set_close_exec(w)
-    return r, w
-
-
 _task_id = None
 
 
@@ -227,19 +219,19 @@ class Subprocess(object):
         pipe_fds = []  # type: List[int]
         to_close = []  # type: List[int]
         if kwargs.get("stdin") is Subprocess.STREAM:
-            in_r, in_w = _pipe_cloexec()
+            in_r, in_w = os.pipe()
             kwargs["stdin"] = in_r
             pipe_fds.extend((in_r, in_w))
             to_close.append(in_r)
             self.stdin = PipeIOStream(in_w)
         if kwargs.get("stdout") is Subprocess.STREAM:
-            out_r, out_w = _pipe_cloexec()
+            out_r, out_w = os.pipe()
             kwargs["stdout"] = out_w
             pipe_fds.extend((out_r, out_w))
             to_close.append(out_w)
             self.stdout = PipeIOStream(out_r)
         if kwargs.get("stderr") is Subprocess.STREAM:
-            err_r, err_w = _pipe_cloexec()
+            err_r, err_w = os.pipe()
             kwargs["stderr"] = err_w
             pipe_fds.extend((err_r, err_w))
             to_close.append(err_w)
index 45d721db64fc33ae88d8d07aae6dce374ee5bf76..e2d682ea64aa8f35fa3de20f416c1f390d45ca38 100644 (file)
@@ -27,7 +27,6 @@ from tornado.ioloop import IOLoop
 from tornado.iostream import IOStream
 from tornado import gen
 from tornado.netutil import Resolver
-from tornado.platform.auto import set_close_exec
 from tornado.gen import TimeoutError
 
 from typing import Any, Union, Dict, Tuple, List, Callable, Iterator, Optional, Set
@@ -311,7 +310,6 @@ class TCPClient(object):
             # - 127.0.0.1 for IPv4
             # - ::1 for IPv6
         socket_obj = socket.socket(af)
-        set_close_exec(socket_obj.fileno())
         if source_port_bind or source_ip_bind:
             # If the user requires binding also to a specific IP/port.
             try:
index 9156be701baf2c60158df0764bf51bd2e0a568fb..43cdf4d91065f4a82a71be774a21a57b65daa472 100644 (file)
@@ -50,7 +50,6 @@ TEST_MODULES = [
     "tornado.test.util_test",
     "tornado.test.web_test",
     "tornado.test.websocket_test",
-    "tornado.test.windows_test",
     "tornado.test.wsgi_test",
 ]
 
diff --git a/tornado/test/windows_test.py b/tornado/test/windows_test.py
deleted file mode 100644 (file)
index 6fe7327..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-import functools
-import os
-import socket
-import unittest
-
-from tornado.platform.auto import set_close_exec
-
-skipIfNonWindows = unittest.skipIf(os.name != "nt", "non-windows platform")
-
-
-@skipIfNonWindows
-class WindowsTest(unittest.TestCase):
-    def test_set_close_exec(self):
-        # set_close_exec works with sockets.
-        s = socket.socket()
-        self.addCleanup(s.close)
-        set_close_exec(s.fileno())
-
-        # But it doesn't work with pipes.
-        r, w = os.pipe()
-        self.addCleanup(functools.partial(os.close, r))
-        self.addCleanup(functools.partial(os.close, w))
-        with self.assertRaises(WindowsError):
-            set_close_exec(r)