diff --git a/Doc/library/os.rst b/Doc/library/os.rst index df136da02cb1fa..0ec0ed18e5cc5b 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -1007,7 +1007,7 @@ or `the MSDN `_ on Windo .. index:: module: pty Open a new pseudo-terminal pair. Return a pair of file descriptors - ``(master, slave)`` for the pty and the tty, respectively. The new file + ``(parent, child)`` for the pty and the tty, respectively. The new file descriptors are :ref:`non-inheritable `. For a (slightly) more portable approach, use the :mod:`pty` module. @@ -3315,7 +3315,7 @@ written in Python, such as a mail server's external command delivery program. Fork a child process, using a new pseudo-terminal as the child's controlling terminal. Return a pair of ``(pid, fd)``, where *pid* is ``0`` in the child, the new child's process id in the parent, and *fd* is the file descriptor of the - master end of the pseudo-terminal. For a more portable approach, use the + parent end of the pseudo-terminal. For a more portable approach, use the :mod:`pty` module. If an error occurs :exc:`OSError` is raised. Availability: some flavors of Unix. diff --git a/Doc/library/pty.rst b/Doc/library/pty.rst index 0ab766065d6e81..f3fd7653c8abb4 100644 --- a/Doc/library/pty.rst +++ b/Doc/library/pty.rst @@ -36,16 +36,16 @@ The :mod:`pty` module defines the following functions: Open a new pseudo-terminal pair, using :func:`os.openpty` if possible, or emulation code for generic Unix systems. Return a pair of file descriptors - ``(master, slave)``, for the master and the slave end, respectively. + ``(parent, child)``, for the parent and the child end, respectively. -.. function:: spawn(argv[, master_read[, stdin_read]]) +.. function:: spawn(argv[, parent_read[, stdin_read]]) Spawn a process, and connect its controlling terminal with the current process's standard io. This is often used to baffle programs which insist on reading from the controlling terminal. - The functions *master_read* and *stdin_read* should be functions which read from + The functions *parent_read* and *stdin_read* should be functions which read from a file descriptor. The defaults try to read 1024 bytes each time they are called. diff --git a/Lib/pty.py b/Lib/pty.py index e841f12f3edb9b..25f061ece8d52c 100644 --- a/Lib/pty.py +++ b/Lib/pty.py @@ -1,6 +1,6 @@ """Pseudo terminal utilities.""" -# Bugs: No signal handling. Doesn't set slave termios and window size. +# Bugs: No signal handling. Doesn't set child termios and window size. # Only tested on Linux. # See: W. Richard Stevens. 1992. Advanced Programming in the # UNIX Environment. Chapter 19. @@ -19,35 +19,35 @@ CHILD = 0 def openpty(): - """openpty() -> (master_fd, slave_fd) - Open a pty master/slave pair, using os.openpty() if possible.""" + """openpty() -> (parent_fd, child_fd) + Open a pty parent/child pair, using os.openpty() if possible.""" try: return os.openpty() except (AttributeError, OSError): pass - master_fd, slave_name = _open_terminal() - slave_fd = slave_open(slave_name) - return master_fd, slave_fd + parent_fd, child_name = _open_terminal() + child_fd = child_open(child_name) + return parent_fd, child_fd -def master_open(): - """master_open() -> (master_fd, slave_name) - Open a pty master and return the fd, and the filename of the slave end. +def parent_open(): + """parent_open() -> (parent_fd, child_name) + Open a pty parent and return the fd, and the filename of the child end. Deprecated, use openpty() instead.""" try: - master_fd, slave_fd = os.openpty() + parent_fd, child_fd = os.openpty() except (AttributeError, OSError): pass else: - slave_name = os.ttyname(slave_fd) - os.close(slave_fd) - return master_fd, slave_name + child_name = os.ttyname(child_fd) + os.close(child_fd) + return parent_fd, child_name return _open_terminal() def _open_terminal(): - """Open pty master and return (master_fd, tty_name).""" + """Open pty parent and return (parent_fd, tty_name).""" for x in 'pqrstuvwxyzPQRST': for y in '0123456789abcdef': pty_name = '/dev/pty' + x + y @@ -58,9 +58,9 @@ def _open_terminal(): return (fd, '/dev/tty' + x + y) raise OSError('out of pty devices') -def slave_open(tty_name): - """slave_open(tty_name) -> slave_fd - Open the pty slave and acquire the controlling terminal, returning +def child_open(tty_name): + """child_open(tty_name) -> child_fd + Open the pty child and acquire the controlling terminal, returning opened filedescriptor. Deprecated, use openpty() instead.""" @@ -76,8 +76,14 @@ def slave_open(tty_name): pass return result +# bpo-34605: master_open()/child_open() has been renamed +# to parent_open()/child_open(), but keep master_open/slave_open aliases +# for backward compatibility. +master_open = parent_open +slave_open = child_open + def fork(): - """fork() -> (pid, master_fd) + """fork() -> (pid, parent_fd) Fork and make the child a session leader with a controlling terminal.""" try: @@ -93,28 +99,28 @@ def fork(): pass return pid, fd - master_fd, slave_fd = openpty() + parent_fd, child_fd = openpty() pid = os.fork() if pid == CHILD: # Establish a new session. os.setsid() - os.close(master_fd) + os.close(parent_fd) - # Slave becomes stdin/stdout/stderr of child. - os.dup2(slave_fd, STDIN_FILENO) - os.dup2(slave_fd, STDOUT_FILENO) - os.dup2(slave_fd, STDERR_FILENO) - if (slave_fd > STDERR_FILENO): - os.close (slave_fd) + # Child becomes stdin/stdout/stderr of child. + os.dup2(child_fd, STDIN_FILENO) + os.dup2(child_fd, STDOUT_FILENO) + os.dup2(child_fd, STDERR_FILENO) + if (child_fd > STDERR_FILENO): + os.close (child_fd) # Explicitly open the tty to make it become a controlling tty. tmp_fd = os.open(os.ttyname(STDOUT_FILENO), os.O_RDWR) os.close(tmp_fd) else: - os.close(slave_fd) + os.close(child_fd) # Parent and child process. - return pid, master_fd + return pid, parent_fd def _writen(fd, data): """Write all the data to a descriptor.""" @@ -126,18 +132,18 @@ def _read(fd): """Default read function.""" return os.read(fd, 1024) -def _copy(master_fd, master_read=_read, stdin_read=_read): +def _copy(parent_fd, parent_read=_read, stdin_read=_read): """Parent copy loop. Copies - pty master -> standard output (master_read) - standard input -> pty master (stdin_read)""" - fds = [master_fd, STDIN_FILENO] + pty parent -> standard output (parent_read) + standard input -> pty parent (stdin_read)""" + fds = [parent_fd, STDIN_FILENO] while True: rfds, wfds, xfds = select(fds, [], []) - if master_fd in rfds: - data = master_read(master_fd) + if parent_fd in rfds: + data = parent_read(parent_fd) if not data: # Reached EOF. - fds.remove(master_fd) + fds.remove(parent_fd) else: os.write(STDOUT_FILENO, data) if STDIN_FILENO in rfds: @@ -145,13 +151,13 @@ def _copy(master_fd, master_read=_read, stdin_read=_read): if not data: fds.remove(STDIN_FILENO) else: - _writen(master_fd, data) + _writen(parent_fd, data) -def spawn(argv, master_read=_read, stdin_read=_read): +def spawn(argv, parent_read=_read, stdin_read=_read): """Create a spawned process.""" if type(argv) == type(''): argv = (argv,) - pid, master_fd = fork() + pid, parent_fd = fork() if pid == CHILD: os.execlp(argv[0], *argv) try: @@ -161,10 +167,10 @@ def spawn(argv, master_read=_read, stdin_read=_read): except tty.error: # This is the same as termios.error restore = 0 try: - _copy(master_fd, master_read, stdin_read) + _copy(parent_fd, parent_read, stdin_read) except OSError: if restore: tty.tcsetattr(STDIN_FILENO, tty.TCSAFLUSH, mode) - os.close(master_fd) + os.close(parent_fd) return os.waitpid(pid, 0)[1] diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py index 11cd950df1cedb..87fc86c5a0b471 100644 --- a/Lib/test/test_asyncio/test_events.py +++ b/Lib/test/test_asyncio/test_events.py @@ -1500,12 +1500,12 @@ async def connect(): def test_read_pty_output(self): proto = MyReadPipeProto(loop=self.loop) - master, slave = os.openpty() - master_read_obj = io.open(master, 'rb', 0) + parent, child = os.openpty() + parent_read_obj = io.open(parent, 'rb', 0) async def connect(): t, p = await self.loop.connect_read_pipe(lambda: proto, - master_read_obj) + parent_read_obj) self.assertIs(p, proto) self.assertIs(t, proto.transport) self.assertEqual(['INITIAL', 'CONNECTED'], proto.state) @@ -1513,16 +1513,16 @@ async def connect(): self.loop.run_until_complete(connect()) - os.write(slave, b'1') + os.write(child, b'1') test_utils.run_until(self.loop, lambda: proto.nbytes) self.assertEqual(1, proto.nbytes) - os.write(slave, b'2345') + os.write(child, b'2345') test_utils.run_until(self.loop, lambda: proto.nbytes >= 5) self.assertEqual(['INITIAL', 'CONNECTED'], proto.state) self.assertEqual(5, proto.nbytes) - os.close(slave) + os.close(child) proto.transport.close() self.loop.run_until_complete(proto.done) self.assertEqual( @@ -1598,11 +1598,11 @@ def test_write_pipe_disconnect_on_close(self): # older than 10.6 (Snow Leopard) @support.requires_mac_ver(10, 6) def test_write_pty(self): - master, slave = os.openpty() - slave_write_obj = io.open(slave, 'wb', 0) + parent, child = os.openpty() + child_write_obj = io.open(child, 'wb', 0) proto = MyWritePipeProto(loop=self.loop) - connect = self.loop.connect_write_pipe(lambda: proto, slave_write_obj) + connect = self.loop.connect_write_pipe(lambda: proto, child_write_obj) transport, p = self.loop.run_until_complete(connect) self.assertIs(p, proto) self.assertIs(transport, proto.transport) @@ -1612,7 +1612,7 @@ def test_write_pty(self): data = bytearray() def reader(data): - chunk = os.read(master, 1024) + chunk = os.read(parent, 1024) data += chunk return len(data) @@ -1626,7 +1626,7 @@ def reader(data): self.assertEqual(b'12345', data) self.assertEqual('CONNECTED', proto.state) - os.close(master) + os.close(parent) # extra info is available self.assertIsNotNone(proto.transport.get_extra_info('pipe')) @@ -1642,14 +1642,14 @@ def reader(data): # older than 10.6 (Snow Leopard) @support.requires_mac_ver(10, 6) def test_bidirectional_pty(self): - master, read_slave = os.openpty() - write_slave = os.dup(read_slave) - tty.setraw(read_slave) + parent, read_child = os.openpty() + write_child = os.dup(read_child) + tty.setraw(read_child) - slave_read_obj = io.open(read_slave, 'rb', 0) + child_read_obj = io.open(read_child, 'rb', 0) read_proto = MyReadPipeProto(loop=self.loop) read_connect = self.loop.connect_read_pipe(lambda: read_proto, - slave_read_obj) + child_read_obj) read_transport, p = self.loop.run_until_complete(read_connect) self.assertIs(p, read_proto) self.assertIs(read_transport, read_proto.transport) @@ -1657,10 +1657,10 @@ def test_bidirectional_pty(self): self.assertEqual(0, read_proto.nbytes) - slave_write_obj = io.open(write_slave, 'wb', 0) + child_write_obj = io.open(write_child, 'wb', 0) write_proto = MyWritePipeProto(loop=self.loop) write_connect = self.loop.connect_write_pipe(lambda: write_proto, - slave_write_obj) + child_write_obj) write_transport, p = self.loop.run_until_complete(write_connect) self.assertIs(p, write_proto) self.assertIs(write_transport, write_proto.transport) @@ -1668,7 +1668,7 @@ def test_bidirectional_pty(self): data = bytearray() def reader(data): - chunk = os.read(master, 1024) + chunk = os.read(parent, 1024) data += chunk return len(data) @@ -1678,7 +1678,7 @@ def reader(data): self.assertEqual(['INITIAL', 'CONNECTED'], read_proto.state) self.assertEqual('CONNECTED', write_proto.state) - os.write(master, b'a') + os.write(parent, b'a') test_utils.run_until(self.loop, lambda: read_proto.nbytes >= 1, timeout=10) self.assertEqual(['INITIAL', 'CONNECTED'], read_proto.state) @@ -1691,14 +1691,14 @@ def reader(data): self.assertEqual(['INITIAL', 'CONNECTED'], read_proto.state) self.assertEqual('CONNECTED', write_proto.state) - os.write(master, b'bcde') + os.write(parent, b'bcde') test_utils.run_until(self.loop, lambda: read_proto.nbytes >= 5, timeout=10) self.assertEqual(['INITIAL', 'CONNECTED'], read_proto.state) self.assertEqual(5, read_proto.nbytes) self.assertEqual('CONNECTED', write_proto.state) - os.close(master) + os.close(parent) read_transport.close() self.loop.run_until_complete(read_proto.done) diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index 233c579356530c..9977cc415d2d01 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -1669,7 +1669,7 @@ def run_child(self, child, terminal_input): # Check the result was got and corresponds to the user's terminal input if len(lines) != 2: # Something went wrong, try to get at stderr - # Beware of Linux raising EIO when the slave is closed + # Beware of Linux raising EIO when the child is closed child_output = bytearray() while True: try: diff --git a/Lib/test/test_openpty.py b/Lib/test/test_openpty.py index 3f46a604025de2..43b2c6ce200058 100644 --- a/Lib/test/test_openpty.py +++ b/Lib/test/test_openpty.py @@ -8,14 +8,14 @@ class OpenptyTest(unittest.TestCase): def test(self): - master, slave = os.openpty() - self.addCleanup(os.close, master) - self.addCleanup(os.close, slave) - if not os.isatty(slave): - self.fail("Slave-end of pty is not a terminal.") + parent, child = os.openpty() + self.addCleanup(os.close, parent) + self.addCleanup(os.close, child) + if not os.isatty(child): + self.fail("Child-end of pty is not a terminal.") - os.write(slave, b'Ping!') - self.assertEqual(os.read(master, 1024), b'Ping!') + os.write(child, b'Ping!') + self.assertEqual(os.read(parent, 1024), b'Ping!') if __name__ == '__main__': unittest.main() diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 6658a61ea2a74a..0330b410e9323b 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -3189,11 +3189,11 @@ def test_dup2(self): @unittest.skipUnless(hasattr(os, 'openpty'), "need os.openpty()") def test_openpty(self): - master_fd, slave_fd = os.openpty() - self.addCleanup(os.close, master_fd) - self.addCleanup(os.close, slave_fd) - self.assertEqual(os.get_inheritable(master_fd), False) - self.assertEqual(os.get_inheritable(slave_fd), False) + parent_fd, child_fd = os.openpty() + self.addCleanup(os.close, parent_fd) + self.addCleanup(os.close, child_fd) + self.assertEqual(os.get_inheritable(parent_fd), False) + self.assertEqual(os.get_inheritable(child_fd), False) class PathTConverterTests(unittest.TestCase): diff --git a/Lib/test/test_pty.py b/Lib/test/test_pty.py index 3b448569a2ffcb..9a10a142cacb18 100644 --- a/Lib/test/test_pty.py +++ b/Lib/test/test_pty.py @@ -78,56 +78,56 @@ def handle_sig(self, sig, frame): def test_basic(self): try: - debug("Calling master_open()") - master_fd, slave_name = pty.master_open() - debug("Got master_fd '%d', slave_name '%s'" % - (master_fd, slave_name)) - debug("Calling slave_open(%r)" % (slave_name,)) - slave_fd = pty.slave_open(slave_name) - debug("Got slave_fd '%d'" % slave_fd) + debug("Calling parent_open()") + parent_fd, child_name = pty.parent_open() + debug("Got parent_fd '%d', child_name '%s'" % + (parent_fd, child_name)) + debug("Calling child_open(%r)" % (child_name,)) + child_fd = pty.child_open(child_name) + debug("Got child_fd '%d'" % child_fd) except OSError: # " An optional feature could not be imported " ... ? raise unittest.SkipTest("Pseudo-terminals (seemingly) not functional.") - self.assertTrue(os.isatty(slave_fd), 'slave_fd is not a tty') + self.assertTrue(os.isatty(child_fd), 'child_fd is not a tty') # Solaris requires reading the fd before anything is returned. - # My guess is that since we open and close the slave fd - # in master_open(), we need to read the EOF. + # My guess is that since we open and close the child fd + # in parent_open(), we need to read the EOF. # Ensure the fd is non-blocking in case there's nothing to read. - blocking = os.get_blocking(master_fd) + blocking = os.get_blocking(parent_fd) try: - os.set_blocking(master_fd, False) + os.set_blocking(parent_fd, False) try: - s1 = os.read(master_fd, 1024) + s1 = os.read(parent_fd, 1024) self.assertEqual(b'', s1) except OSError as e: if e.errno != errno.EAGAIN: raise finally: # Restore the original flags. - os.set_blocking(master_fd, blocking) + os.set_blocking(parent_fd, blocking) - debug("Writing to slave_fd") - os.write(slave_fd, TEST_STRING_1) - s1 = _readline(master_fd) + debug("Writing to child_fd") + os.write(child_fd, TEST_STRING_1) + s1 = _readline(parent_fd) self.assertEqual(b'I wish to buy a fish license.\n', normalize_output(s1)) debug("Writing chunked output") - os.write(slave_fd, TEST_STRING_2[:5]) - os.write(slave_fd, TEST_STRING_2[5:]) - s2 = _readline(master_fd) + os.write(child_fd, TEST_STRING_2[:5]) + os.write(child_fd, TEST_STRING_2[5:]) + s2 = _readline(parent_fd) self.assertEqual(b'For my pet fish, Eric.\n', normalize_output(s2)) - os.close(slave_fd) - os.close(master_fd) + os.close(child_fd) + os.close(parent_fd) def test_fork(self): debug("calling pty.fork()") - pid, master_fd = pty.fork() + pid, parent_fd = pty.fork() if pid == pty.CHILD: # stdout should be connected to a tty. if not os.isatty(1): @@ -172,7 +172,7 @@ def test_fork(self): # worth checking for EIO. while True: try: - data = os.read(master_fd, 80) + data = os.read(parent_fd, 80) except OSError: break if not data: @@ -180,7 +180,7 @@ def test_fork(self): sys.stdout.write(str(data.replace(b'\r\n', b'\n'), encoding='ascii')) - ##line = os.read(master_fd, 80) + ##line = os.read(parent_fd, 80) ##lines = line.replace('\r\n', '\n').split('\n') ##if False and lines != ['In child, calling os.setsid()', ## 'Good: OSError was raised.', '']: @@ -198,15 +198,15 @@ def test_fork(self): elif res != 4: self.fail("pty.fork() failed for unknown reasons.") - ##debug("Reading from master_fd now that the child has exited") + ##debug("Reading from parent_fd now that the child has exited") ##try: - ## s1 = os.read(master_fd, 1024) + ## s1 = os.read(parent_fd, 1024) ##except OSError: ## pass ##else: - ## raise TestFailed("Read from master_fd did not raise exception") + ## raise TestFailed("Read from parent_fd did not raise exception") - os.close(master_fd) + os.close(parent_fd) # pty.fork() passed. @@ -254,41 +254,41 @@ def _mock_select(self, rfds, wfds, xfds): return self.select_rfds_results.pop(0), [], [] def test__copy_to_each(self): - """Test the normal data case on both master_fd and stdin.""" + """Test the normal data case on both parent_fd and stdin.""" read_from_stdout_fd, mock_stdout_fd = self._pipe() pty.STDOUT_FILENO = mock_stdout_fd mock_stdin_fd, write_to_stdin_fd = self._pipe() pty.STDIN_FILENO = mock_stdin_fd socketpair = self._socketpair() - masters = [s.fileno() for s in socketpair] + parents = [s.fileno() for s in socketpair] # Feed data. Smaller than PIPEBUF. These writes will not block. - os.write(masters[1], b'from master') + os.write(parents[1], b'from parent') os.write(write_to_stdin_fd, b'from stdin') # Expect two select calls, the last one will cause IndexError pty.select = self._mock_select self.select_rfds_lengths.append(2) - self.select_rfds_results.append([mock_stdin_fd, masters[0]]) + self.select_rfds_results.append([mock_stdin_fd, parents[0]]) self.select_rfds_lengths.append(2) with self.assertRaises(IndexError): - pty._copy(masters[0]) + pty._copy(parents[0]) # Test that the right data went to the right places. - rfds = select.select([read_from_stdout_fd, masters[1]], [], [], 0)[0] - self.assertEqual([read_from_stdout_fd, masters[1]], rfds) - self.assertEqual(os.read(read_from_stdout_fd, 20), b'from master') - self.assertEqual(os.read(masters[1], 20), b'from stdin') + rfds = select.select([read_from_stdout_fd, parents[1]], [], [], 0)[0] + self.assertEqual([read_from_stdout_fd, parents[1]], rfds) + self.assertEqual(os.read(read_from_stdout_fd, 20), b'from parent') + self.assertEqual(os.read(parents[1], 20), b'from stdin') def test__copy_eof_on_all(self): - """Test the empty read EOF case on both master_fd and stdin.""" + """Test the empty read EOF case on both parent_fd and stdin.""" read_from_stdout_fd, mock_stdout_fd = self._pipe() pty.STDOUT_FILENO = mock_stdout_fd mock_stdin_fd, write_to_stdin_fd = self._pipe() pty.STDIN_FILENO = mock_stdin_fd socketpair = self._socketpair() - masters = [s.fileno() for s in socketpair] + parents = [s.fileno() for s in socketpair] socketpair[1].close() os.close(write_to_stdin_fd) @@ -296,13 +296,13 @@ def test__copy_eof_on_all(self): # Expect two select calls, the last one will cause IndexError pty.select = self._mock_select self.select_rfds_lengths.append(2) - self.select_rfds_results.append([mock_stdin_fd, masters[0]]) + self.select_rfds_results.append([mock_stdin_fd, parents[0]]) # We expect that both fds were removed from the fds list as they # both encountered an EOF before the second select call. self.select_rfds_lengths.append(0) with self.assertRaises(IndexError): - pty._copy(masters[0]) + pty._copy(parents[0]) def tearDownModule(): diff --git a/Lib/test/test_readline.py b/Lib/test/test_readline.py index 67ee9b7f7cfb1f..2462897818d776 100644 --- a/Lib/test/test_readline.py +++ b/Lib/test/test_readline.py @@ -282,10 +282,10 @@ def test_history_size(self): def run_pty(script, input=b"dummy input\r", env=None): pty = import_module('pty') output = bytearray() - [master, slave] = pty.openpty() + [parent, child] = pty.openpty() args = (sys.executable, '-c', script) - proc = subprocess.Popen(args, stdin=slave, stdout=slave, stderr=slave, env=env) - os.close(slave) + proc = subprocess.Popen(args, stdin=child, stdout=child, stderr=child, env=env) + os.close(child) with ExitStack() as cleanup: cleanup.enter_context(proc) def terminate(proc): @@ -295,22 +295,22 @@ def terminate(proc): # Workaround for Open/Net BSD bug (Issue 16762) pass cleanup.callback(terminate, proc) - cleanup.callback(os.close, master) + cleanup.callback(os.close, parent) # Avoid using DefaultSelector and PollSelector. Kqueue() does not # work with pseudo-terminals on OS X < 10.9 (Issue 20365) and Open # BSD (Issue 20667). Poll() does not work with OS X 10.6 or 10.4 # either (Issue 20472). Hopefully the file descriptor is low enough # to use with select(). sel = cleanup.enter_context(selectors.SelectSelector()) - sel.register(master, selectors.EVENT_READ | selectors.EVENT_WRITE) - os.set_blocking(master, False) + sel.register(parent, selectors.EVENT_READ | selectors.EVENT_WRITE) + os.set_blocking(parent, False) while True: for [_, events] in sel.select(): if events & selectors.EVENT_READ: try: - chunk = os.read(master, 0x10000) + chunk = os.read(parent, 0x10000) except OSError as err: - # Linux raises EIO when slave is closed (Issue 5380) + # Linux raises EIO when child is closed (Issue 5380) if err.errno != EIO: raise chunk = b"" @@ -319,14 +319,14 @@ def terminate(proc): output.extend(chunk) if events & selectors.EVENT_WRITE: try: - input = input[os.write(master, input):] + input = input[os.write(parent, input):] except OSError as err: - # Apparently EIO means the slave was closed + # Apparently EIO means the child was closed if err.errno != EIO: raise input = b"" # Stop writing if not input: - sel.modify(master, selectors.EVENT_READ) + sel.modify(parent, selectors.EVENT_READ) if __name__ == "__main__": diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index 7a2188504ac57e..130f64587e16a0 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -2343,8 +2343,8 @@ PyDoc_STRVAR(os_openpty__doc__, "\n" "Open a pseudo-terminal.\n" "\n" -"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n" -"for both the master and slave ends."); +"Return a tuple of (parent_fd, child_fd) containing open file descriptors\n" +"for both the parent and child ends."); #define OS_OPENPTY_METHODDEF \ {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__}, @@ -2368,7 +2368,7 @@ PyDoc_STRVAR(os_forkpty__doc__, "\n" "Fork a new process with a new pseudo-terminal as controlling tty.\n" "\n" -"Returns a tuple of (pid, master_fd).\n" +"Returns a tuple of (pid, parent_fd).\n" "Like fork(), return pid of 0 to the child process,\n" "and pid of child to the parent process.\n" "To both, return fd of newly opened pseudo-terminal."); @@ -3927,7 +3927,7 @@ PyDoc_STRVAR(os_isatty__doc__, "Return True if the fd is connected to a terminal.\n" "\n" "Return True if the file descriptor is an open file descriptor\n" -"connected to the slave end of a terminal."); +"connected to the child end of a terminal."); #define OS_ISATTY_METHODDEF \ {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__}, @@ -6627,4 +6627,4 @@ os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject #ifndef OS_GETRANDOM_METHODDEF #define OS_GETRANDOM_METHODDEF #endif /* !defined(OS_GETRANDOM_METHODDEF) */ -/*[clinic end generated code: output=47fb6a3e88cba6d9 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=d4aee56f190a791d input=a9049054013a1b77]*/ diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 7f13735eadc8bd..5e6325fe910665 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -6199,17 +6199,17 @@ os.openpty Open a pseudo-terminal. -Return a tuple of (master_fd, slave_fd) containing open file descriptors -for both the master and slave ends. +Return a tuple of (parent_fd, child_fd) containing open file descriptors +for both the parent and child ends. [clinic start generated code]*/ static PyObject * os_openpty_impl(PyObject *module) -/*[clinic end generated code: output=98841ce5ec9cef3c input=f3d99fd99e762907]*/ +/*[clinic end generated code: output=98841ce5ec9cef3c input=81a3a9d6a23e56a3]*/ { - int master_fd = -1, slave_fd = -1; + int parent_fd = -1, child_fd = -1; #ifndef HAVE_OPENPTY - char * slave_name; + char * child_name; #endif #if defined(HAVE_DEV_PTMX) && !defined(HAVE_OPENPTY) && !defined(HAVE__GETPTY) PyOS_sighandler_t sig_saved; @@ -6219,75 +6219,75 @@ os_openpty_impl(PyObject *module) #endif #ifdef HAVE_OPENPTY - if (openpty(&master_fd, &slave_fd, NULL, NULL, NULL) != 0) + if (openpty(&parent_fd, &child_fd, NULL, NULL, NULL) != 0) goto posix_error; - if (_Py_set_inheritable(master_fd, 0, NULL) < 0) + if (_Py_set_inheritable(parent_fd, 0, NULL) < 0) goto error; - if (_Py_set_inheritable(slave_fd, 0, NULL) < 0) + if (_Py_set_inheritable(child_fd, 0, NULL) < 0) goto error; #elif defined(HAVE__GETPTY) - slave_name = _getpty(&master_fd, O_RDWR, 0666, 0); - if (slave_name == NULL) + child_name = _getpty(&parent_fd, O_RDWR, 0666, 0); + if (child_name == NULL) goto posix_error; - if (_Py_set_inheritable(master_fd, 0, NULL) < 0) + if (_Py_set_inheritable(parent_fd, 0, NULL) < 0) goto error; - slave_fd = _Py_open(slave_name, O_RDWR); - if (slave_fd < 0) + child_fd = _Py_open(child_name, O_RDWR); + if (child_fd < 0) goto error; #else - master_fd = open(DEV_PTY_FILE, O_RDWR | O_NOCTTY); /* open master */ - if (master_fd < 0) + parent_fd = open(DEV_PTY_FILE, O_RDWR | O_NOCTTY); /* open parent */ + if (parent_fd < 0) goto posix_error; sig_saved = PyOS_setsig(SIGCHLD, SIG_DFL); - /* change permission of slave */ - if (grantpt(master_fd) < 0) { + /* change permission of child */ + if (grantpt(parent_fd) < 0) { PyOS_setsig(SIGCHLD, sig_saved); goto posix_error; } - /* unlock slave */ - if (unlockpt(master_fd) < 0) { + /* unlock child */ + if (unlockpt(parent_fd) < 0) { PyOS_setsig(SIGCHLD, sig_saved); goto posix_error; } PyOS_setsig(SIGCHLD, sig_saved); - slave_name = ptsname(master_fd); /* get name of slave */ - if (slave_name == NULL) + child_name = ptsname(parent_fd); /* get name of child */ + if (child_name == NULL) goto posix_error; - slave_fd = _Py_open(slave_name, O_RDWR | O_NOCTTY); /* open slave */ - if (slave_fd == -1) + child_fd = _Py_open(child_name, O_RDWR | O_NOCTTY); /* open child */ + if (child_fd == -1) goto error; - if (_Py_set_inheritable(master_fd, 0, NULL) < 0) + if (_Py_set_inheritable(parent_fd, 0, NULL) < 0) goto posix_error; #if !defined(__CYGWIN__) && !defined(__ANDROID__) && !defined(HAVE_DEV_PTC) - ioctl(slave_fd, I_PUSH, "ptem"); /* push ptem */ - ioctl(slave_fd, I_PUSH, "ldterm"); /* push ldterm */ + ioctl(child_fd, I_PUSH, "ptem"); /* push ptem */ + ioctl(child_fd, I_PUSH, "ldterm"); /* push ldterm */ #ifndef __hpux - ioctl(slave_fd, I_PUSH, "ttcompat"); /* push ttcompat */ + ioctl(child_fd, I_PUSH, "ttcompat"); /* push ttcompat */ #endif /* __hpux */ #endif /* HAVE_CYGWIN */ #endif /* HAVE_OPENPTY */ - return Py_BuildValue("(ii)", master_fd, slave_fd); + return Py_BuildValue("(ii)", parent_fd, child_fd); posix_error: posix_error(); error: - if (master_fd != -1) - close(master_fd); - if (slave_fd != -1) - close(slave_fd); + if (parent_fd != -1) + close(parent_fd); + if (child_fd != -1) + close(child_fd); return NULL; } #endif /* defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX) */ @@ -6299,7 +6299,7 @@ os.forkpty Fork a new process with a new pseudo-terminal as controlling tty. -Returns a tuple of (pid, master_fd). +Returns a tuple of (pid, parent_fd). Like fork(), return pid of 0 to the child process, and pid of child to the parent process. To both, return fd of newly opened pseudo-terminal. @@ -6307,13 +6307,13 @@ To both, return fd of newly opened pseudo-terminal. static PyObject * os_forkpty_impl(PyObject *module) -/*[clinic end generated code: output=60d0a5c7512e4087 input=f1f7f4bae3966010]*/ +/*[clinic end generated code: output=60d0a5c7512e4087 input=37fa8984e7c77147]*/ { - int master_fd = -1; + int parent_fd = -1; pid_t pid; PyOS_BeforeFork(); - pid = forkpty(&master_fd, NULL, NULL, NULL); + pid = forkpty(&parent_fd, NULL, NULL, NULL); if (pid == 0) { /* child: this clobbers and resets the import lock. */ PyOS_AfterFork_Child(); @@ -6323,7 +6323,7 @@ os_forkpty_impl(PyObject *module) } if (pid == -1) return posix_error(); - return Py_BuildValue("(Ni)", PyLong_FromPid(pid), master_fd); + return Py_BuildValue("(Ni)", PyLong_FromPid(pid), parent_fd); } #endif /* HAVE_FORKPTY */ @@ -8820,12 +8820,12 @@ os.isatty -> bool Return True if the fd is connected to a terminal. Return True if the file descriptor is an open file descriptor -connected to the slave end of a terminal. +connected to the child end of a terminal. [clinic start generated code]*/ static int os_isatty_impl(PyObject *module, int fd) -/*[clinic end generated code: output=6a48c8b4e644ca00 input=08ce94aa1eaf7b5e]*/ +/*[clinic end generated code: output=6a48c8b4e644ca00 input=84b2bbf7efe5ebc0]*/ { int return_value; _Py_BEGIN_SUPPRESS_IPH