Skip to content

Commit 5c0c325

Browse files
benjaminpmiss-islington
authored andcommitted
closes bpo-38713: Expose P_PIDFD in os if it's defined. (GH-17071)
https://bugs.python.org/issue38713
1 parent 6c4c45e commit 5c0c325

File tree

7 files changed

+40
-6
lines changed

7 files changed

+40
-6
lines changed

Doc/library/os.rst

+11-1
Original file line numberDiff line numberDiff line change
@@ -3921,7 +3921,8 @@ written in Python, such as a mail server's external command delivery program.
39213921
.. function:: waitid(idtype, id, options)
39223922

39233923
Wait for the completion of one or more child processes.
3924-
*idtype* can be :data:`P_PID`, :data:`P_PGID` or :data:`P_ALL`.
3924+
*idtype* can be :data:`P_PID`, :data:`P_PGID`, :data:`P_ALL`, or
3925+
:data:`P_PIDFD` on Linux.
39253926
*id* specifies the pid to wait on.
39263927
*options* is constructed from the ORing of one or more of :data:`WEXITED`,
39273928
:data:`WSTOPPED` or :data:`WCONTINUED` and additionally may be ORed with
@@ -3946,6 +3947,15 @@ written in Python, such as a mail server's external command delivery program.
39463947

39473948
.. versionadded:: 3.3
39483949

3950+
.. data:: P_PIDFD
3951+
3952+
This is a Linux-specific *idtype* that indicates that *id* is a file
3953+
descriptor that refers to a process.
3954+
3955+
.. availability:: Linux 5.4+
3956+
3957+
.. versionadded:: 3.9
3958+
39493959
.. data:: WEXITED
39503960
WSTOPPED
39513961
WNOWAIT

Doc/whatsnew/3.9.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,9 @@ os
150150
Added :data:`~os.CLD_KILLED` and :data:`~os.CLD_STOPPED` for :attr:`si_code`.
151151
(Contributed by Dong-hee Na in :issue:`38493`.)
152152

153-
Exposed the Linux-specific :func:`os.pidfd_open` for process management with
154-
file descriptors. (:issue:`38692`)
153+
Exposed the Linux-specific :func:`os.pidfd_open` (:issue:`38692`) and
154+
:data:`os.P_PIDFD` (:issue:`38713`) for process management with file
155+
descriptors.
155156

156157
threading
157158
---------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add :data:`os.P_PIDFD` constant, which may be passed to :func:`os.waitid` to
2+
wait on a Linux process file descriptor.

Modules/posixmodule.c

+6
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ corresponding Unix manual entries for more information on calls.");
8585
#ifdef HAVE_SYS_WAIT_H
8686
#include <sys/wait.h> /* For WNOHANG */
8787
#endif
88+
#ifdef HAVE_LINUX_WAIT_H
89+
#include <linux/wait.h> // For P_PIDFD
90+
#endif
8891

8992
#ifdef HAVE_SIGNAL_H
9093
#include <signal.h>
@@ -14099,6 +14102,9 @@ all_ins(PyObject *m)
1409914102
if (PyModule_AddIntMacro(m, P_PID)) return -1;
1410014103
if (PyModule_AddIntMacro(m, P_PGID)) return -1;
1410114104
if (PyModule_AddIntMacro(m, P_ALL)) return -1;
14105+
#ifdef P_PIDFD
14106+
if (PyModule_AddIntMacro(m, P_PIDFD)) return -1;
14107+
#endif
1410214108
#endif
1410314109
#ifdef WEXITED
1410414110
if (PyModule_AddIntMacro(m, WEXITED)) return -1;

configure

+14-2
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ infodir
782782
docdir
783783
oldincludedir
784784
includedir
785+
runstatedir
785786
localstatedir
786787
sharedstatedir
787788
sysconfdir
@@ -895,6 +896,7 @@ datadir='${datarootdir}'
895896
sysconfdir='${prefix}/etc'
896897
sharedstatedir='${prefix}/com'
897898
localstatedir='${prefix}/var'
899+
runstatedir='${localstatedir}/run'
898900
includedir='${prefix}/include'
899901
oldincludedir='/usr/include'
900902
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
@@ -1147,6 +1149,15 @@ do
11471149
| -silent | --silent | --silen | --sile | --sil)
11481150
silent=yes ;;
11491151

1152+
-runstatedir | --runstatedir | --runstatedi | --runstated \
1153+
| --runstate | --runstat | --runsta | --runst | --runs \
1154+
| --run | --ru | --r)
1155+
ac_prev=runstatedir ;;
1156+
-runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
1157+
| --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
1158+
| --run=* | --ru=* | --r=*)
1159+
runstatedir=$ac_optarg ;;
1160+
11501161
-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
11511162
ac_prev=sbindir ;;
11521163
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@@ -1284,7 +1295,7 @@ fi
12841295
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
12851296
datadir sysconfdir sharedstatedir localstatedir includedir \
12861297
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
1287-
libdir localedir mandir
1298+
libdir localedir mandir runstatedir
12881299
do
12891300
eval ac_val=\$$ac_var
12901301
# Remove trailing slashes.
@@ -1437,6 +1448,7 @@ Fine tuning of the installation directories:
14371448
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
14381449
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
14391450
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
1451+
--runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
14401452
--libdir=DIR object code libraries [EPREFIX/lib]
14411453
--includedir=DIR C header files [PREFIX/include]
14421454
--oldincludedir=DIR C header files for non-gcc [/usr/include]
@@ -7917,7 +7929,7 @@ sys/stat.h sys/syscall.h sys/sys_domain.h sys/termio.h sys/time.h \
79177929
sys/times.h sys/types.h sys/uio.h sys/un.h sys/utsname.h sys/wait.h pty.h \
79187930
libutil.h sys/resource.h netpacket/packet.h sysexits.h bluetooth.h \
79197931
linux/tipc.h linux/random.h spawn.h util.h alloca.h endian.h \
7920-
sys/endian.h sys/sysmacros.h linux/memfd.h sys/memfd.h sys/mman.h
7932+
sys/endian.h sys/sysmacros.h linux/memfd.h linux/wait.h sys/memfd.h sys/mman.h
79217933
do :
79227934
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
79237935
ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"

configure.ac

+1-1
Original file line numberDiff line numberDiff line change
@@ -2161,7 +2161,7 @@ sys/stat.h sys/syscall.h sys/sys_domain.h sys/termio.h sys/time.h \
21612161
sys/times.h sys/types.h sys/uio.h sys/un.h sys/utsname.h sys/wait.h pty.h \
21622162
libutil.h sys/resource.h netpacket/packet.h sysexits.h bluetooth.h \
21632163
linux/tipc.h linux/random.h spawn.h util.h alloca.h endian.h \
2164-
sys/endian.h sys/sysmacros.h linux/memfd.h sys/memfd.h sys/mman.h)
2164+
sys/endian.h sys/sysmacros.h linux/memfd.h linux/wait.h sys/memfd.h sys/mman.h)
21652165
AC_HEADER_DIRENT
21662166
AC_HEADER_MAJOR
21672167

pyconfig.h.in

+3
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,9 @@
642642
/* Define to 1 if you have the <linux/vm_sockets.h> header file. */
643643
#undef HAVE_LINUX_VM_SOCKETS_H
644644

645+
/* Define to 1 if you have the <linux/wait.h> header file. */
646+
#undef HAVE_LINUX_WAIT_H
647+
645648
/* Define to 1 if you have the `lockf' function. */
646649
#undef HAVE_LOCKF
647650

0 commit comments

Comments
 (0)