Skip to content

Commit 255bf5b

Browse files
committed
Issue python#16962: Use getdents64 instead of the obsolete getdents syscall in
the subprocess module on Linux.
1 parent bce9a5d commit 255bf5b

2 files changed

Lines changed: 11 additions & 17 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ Core and Builtins
191191
Library
192192
-------
193193

194+
- Issue #16962: Use getdents64 instead of the obsolete getdents syscall
195+
in the subprocess module on Linux.
196+
194197
- Issue #17018: Make Process.join() retry if os.waitpid() fails with EINTR.
195198

196199
- Issue #14720: sqlite3: Convert datetime microseconds correctly.
@@ -626,9 +629,6 @@ Library
626629
- Issue #15906: Fix a regression in `argparse` caused by the preceding change,
627630
when ``action='append'``, ``type='str'`` and ``default=[]``.
628631

629-
Extension Modules
630-
-----------------
631-
632632
- Issue #12268: The io module file object write methods no longer abort early
633633
when one of its write system calls is interrupted (EINTR).
634634

Modules/_posixsubprocess.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,11 @@ _close_fds_by_brute_force(int start_fd, int end_fd, PyObject *py_fds_to_keep)
176176
* This structure is very old and stable: It will not change unless the kernel
177177
* chooses to break compatibility with all existing binaries. Highly Unlikely.
178178
*/
179-
struct linux_dirent {
180-
#if defined(__x86_64__) && defined(__ILP32__)
181-
/* Support the wacky x32 ABI (fake 32-bit userspace speaking to x86_64
182-
* kernel interfaces) - https://sites.google.com/site/x32abi/ */
179+
struct linux_dirent64 {
183180
unsigned long long d_ino;
184-
unsigned long long d_off;
185-
#else
186-
unsigned long d_ino; /* Inode number */
187-
unsigned long d_off; /* Offset to next linux_dirent */
188-
#endif
181+
long long d_off;
189182
unsigned short d_reclen; /* Length of this linux_dirent */
183+
unsigned char d_type;
190184
char d_name[256]; /* Filename (null-terminated) */
191185
};
192186

@@ -228,16 +222,16 @@ _close_open_fd_range_safe(int start_fd, int end_fd, PyObject* py_fds_to_keep)
228222
_close_fds_by_brute_force(start_fd, end_fd, py_fds_to_keep);
229223
return;
230224
} else {
231-
char buffer[sizeof(struct linux_dirent)];
225+
char buffer[sizeof(struct linux_dirent64)];
232226
int bytes;
233-
while ((bytes = syscall(SYS_getdents, fd_dir_fd,
234-
(struct linux_dirent *)buffer,
227+
while ((bytes = syscall(SYS_getdents64, fd_dir_fd,
228+
(struct linux_dirent64 *)buffer,
235229
sizeof(buffer))) > 0) {
236-
struct linux_dirent *entry;
230+
struct linux_dirent64 *entry;
237231
int offset;
238232
for (offset = 0; offset < bytes; offset += entry->d_reclen) {
239233
int fd;
240-
entry = (struct linux_dirent *)(buffer + offset);
234+
entry = (struct linux_dirent64 *)(buffer + offset);
241235
if ((fd = _pos_int_from_ascii(entry->d_name)) < 0)
242236
continue; /* Not a number. */
243237
if (fd != fd_dir_fd && fd >= start_fd && fd < end_fd &&

0 commit comments

Comments
 (0)