Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions Lib/test/test_os/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -3970,12 +3970,7 @@ def test_does_not_crash(self):
try:
size = os.get_terminal_size()
except OSError as e:
known_errnos = [errno.EINVAL, errno.ENOTTY]
if sys.platform == "android":
# The Android testbed redirects the native stdout to a pipe,
# which returns a different error code.
known_errnos.append(errno.EACCES)
if sys.platform == "win32" or e.errno in known_errnos:
if sys.platform == "win32" or e.errno in (errno.EINVAL, errno.ENOTTY):
# Under win32 a generic OSError can be thrown if the
# handle cannot be retrieved
self.skipTest("failed to query terminal size")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:func:`os.get_terminal_size` now checks ``isatty`` before calling ``ioctl``,
which reduces log noise on Android.
7 changes: 7 additions & 0 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -15971,6 +15971,13 @@ os_get_terminal_size_impl(PyObject *module, int fd)

#ifdef TERMSIZE_USE_IOCTL
{
// On Android, stdout is probably not connected, and calling TIOCGWINSZ
// on an invalid file descriptor causes a log message "avc: denied {
// ioctl }". Some common tools such as pytest call get_terminal_size
// very often, so check it's a TTY first to avoid cluttering the log.
if (!isatty(fd))
return PyErr_SetFromErrno(PyExc_OSError);

struct winsize w;
if (ioctl(fd, TIOCGWINSZ, &w))
return PyErr_SetFromErrno(PyExc_OSError);
Expand Down
Loading