From 576bc5a3cdbf2959b151dc3514c2778214f6b0c2 Mon Sep 17 00:00:00 2001 From: Soumendra Ganguly Date: Sat, 20 Nov 2021 03:51:54 -0600 Subject: [PATCH 01/13] Add os.login_tty() for Unix. Signed-off-by: Soumendra Ganguly --- Doc/library/os.rst | 11 ++++ Modules/clinic/posixmodule.c.h | 41 ++++++++++++- Modules/posixmodule.c | 103 +++++++++++++++++++++++++++++---- configure | 101 +++++++++++++++++++++++++++++++- configure.ac | 10 +++- 5 files changed, 250 insertions(+), 16 deletions(-) diff --git a/Doc/library/os.rst b/Doc/library/os.rst index 8092397be650f9..e47aec2ec1bc83 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -991,6 +991,17 @@ as internal buffering of data. .. versionadded:: 3.3 +.. function:: login_tty(fd) + + Prepare the tty of which fd is a file descriptor for a new login session. + Make the calling process a session leader; make the tty the controlling tty, + the stdin, the stdout, and the stderr of the calling process; close fd. + + .. availability:: Unix. + + .. versionadded:: 3.11 + + .. function:: lseek(fd, pos, how) Set the current position of file descriptor *fd* to position *pos*, modified diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index 7921c222b90091..d48f6ebd0a1f5c 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -3070,6 +3070,41 @@ os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored)) #endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */ +#if (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) + +PyDoc_STRVAR(os_login_tty__doc__, +"login_tty($module, fd, /)\n" +"--\n" +"\n" +"Prepare the tty of which fd is a file descriptor for a new login session.\n" +"\n" +"Make the calling process a session leader; make the tty the\n" +"controlling tty, the stdin, the stdout, and the stderr of the\n" +"calling process; close fd."); + +#define OS_LOGIN_TTY_METHODDEF \ + {"login_tty", (PyCFunction)os_login_tty, METH_O, os_login_tty__doc__}, + +static PyObject * +os_login_tty_impl(PyObject *module, int fd); + +static PyObject * +os_login_tty(PyObject *module, PyObject *arg) +{ + PyObject *return_value = NULL; + int fd; + + if (!_PyLong_FileDescriptor_Converter(arg, &fd)) { + goto exit; + } + return_value = os_login_tty_impl(module, fd); + +exit: + return return_value; +} + +#endif /* (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) */ + #if defined(HAVE_FORKPTY) PyDoc_STRVAR(os_forkpty__doc__, @@ -8864,6 +8899,10 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na #define OS_OPENPTY_METHODDEF #endif /* !defined(OS_OPENPTY_METHODDEF) */ +#ifndef OS_LOGIN_TTY_METHODDEF + #define OS_LOGIN_TTY_METHODDEF +#endif /* !defined(OS_LOGIN_TTY_METHODDEF) */ + #ifndef OS_FORKPTY_METHODDEF #define OS_FORKPTY_METHODDEF #endif /* !defined(OS_FORKPTY_METHODDEF) */ @@ -9263,4 +9302,4 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ -/*[clinic end generated code: output=65a85d7d3f2c487e input=a9049054013a1b77]*/ +/*[clinic end generated code: output=56182b66cd71a276 input=a9049054013a1b77]*/ diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 667a3339f5ba8e..b816debfdf5a89 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -7196,22 +7196,21 @@ os_sched_getaffinity_impl(PyObject *module, pid_t pid) # define DEV_PTY_FILE "/dev/ptmx" #endif -#if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || defined(HAVE_DEV_PTMX) -#ifdef HAVE_PTY_H +#if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || defined(HAVE_LOGIN_TTY) || defined(HAVE_DEV_PTMX) +#if defined(HAVE_PTY_H) #include -#else -#ifdef HAVE_LIBUTIL_H +#if defined(HAVE_UTMP_H) +#include +#endif /* HAVE_UTMP_H */ +#elif defined(HAVE_LIBUTIL_H) #include -#else -#ifdef HAVE_UTIL_H +#elif defined(HAVE_UTIL_H) #include -#endif /* HAVE_UTIL_H */ -#endif /* HAVE_LIBUTIL_H */ #endif /* HAVE_PTY_H */ -#ifdef HAVE_STROPTS_H +#if defined(HAVE_STROPTS_H) #include #endif -#endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || defined(HAVE_DEV_PTMX) */ +#endif /* if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || defined(HAVE_LOGIN_TTY) || defined(HAVE_DEV_PTMX) */ #if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX) @@ -7314,6 +7313,86 @@ os_openpty_impl(PyObject *module) #endif /* defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX) */ +#if defined(HAVE_SETSID) +#if defined(TIOCSCTTY) || defined(HAVE_TTYNAME) +#define HAVE_FALLBACK_LOGIN_TTY 1 +#endif /* defined(TIOCSCTTY) || defined(HAVE_TTYNAME) */ +#endif /* HAVE_SETSID */ + +#if defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY) +/*[clinic input] +os.login_tty + + fd: fildes + / + +Prepare the tty of which fd is a file descriptor for a new login session. + +Make the calling process a session leader; make the tty the +controlling tty, the stdin, the stdout, and the stderr of the +calling process; close fd. +[clinic start generated code]*/ + +static PyObject * +os_login_tty_impl(PyObject *module, int fd) +/*[clinic end generated code: output=495a79911b4cc1bc input=5f298565099903a2]*/ +{ +#if defined(HAVE_LOGIN_TTY) + if (login_tty(fd) == -1) { + return posix_error(); + } +#else /* defined(HAVE_FALLBACK_LOGIN_TTY) */ + /* Establish a new session. */ + if (setsid() == -1) { + return posix_error(); + } + + /* The tty becomes the controlling terminal. */ +#if defined(TIOCSCTTY) + if (ioctl(fd, TIOCSCTTY, (char *)NULL) == -1) { + return posix_error(); + } +#else /* defined(HAVE_TTYNAME) */ + /* Fallback method (archaic); from Advanced Programming in the UNIX(R) + * Environment, Third edition, 2013, Section 9.6 - Controlling Terminal: + * "Systems derived from UNIX System V allocate the controlling + * terminal for a session when the session leader opens the first + * terminal device that is not already associated with a session, as + * long as the call to open does not specify the O_NOCTTY flag." */ + char *tmppath = ttyname(fd); + if (tmppath == NULL) { + return posix_error(); + } + +#define CLOSE_IF_NOT_FD(otherfd) \ + if (fd != otherfd) { \ + close(otherfd); \ + } \ + + CLOSE_IF_NOT_FD(0); + CLOSE_IF_NOT_FD(1); + CLOSE_IF_NOT_FD(2); + + int tmpfd = open(tmppath, O_RDWR); + if (tmpfd == -1) { + return posix_error(); + } + close(tmpfd); +#endif /* defined(TIOCSCTTY) */ + + /* The tty becomes stdin/stdout/stderr */ + if (dup2(fd, 0) == -1 || dup2(fd, 1) == -1 || dup2(fd, 2) == -1) { + return posix_error(); + } + if (fd > 2) { + close(fd); + } +#endif /* defined(HAVE_LOGIN_TTY) */ + Py_RETURN_NONE; +} +#endif /* defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY) */ + + #ifdef HAVE_FORKPTY /*[clinic input] os.forkpty @@ -7349,8 +7428,9 @@ os_forkpty_impl(PyObject *module) /* parent: release the import lock. */ PyOS_AfterFork_Parent(); } - if (pid == -1) + if (pid == -1) { return posix_error(); + } return Py_BuildValue("(Ni)", PyLong_FromPid(pid), master_fd); } #endif /* HAVE_FORKPTY */ @@ -14745,6 +14825,7 @@ static PyMethodDef posix_methods[] = { OS_SCHED_SETAFFINITY_METHODDEF OS_SCHED_GETAFFINITY_METHODDEF OS_OPENPTY_METHODDEF + OS_LOGIN_TTY_METHODDEF OS_FORKPTY_METHODDEF OS_GETEGID_METHODDEF OS_GETEUID_METHODDEF diff --git a/configure b/configure index e8935dfb625fe0..43fbfbe9aa84fc 100755 --- a/configure +++ b/configure @@ -8176,7 +8176,7 @@ sys/audioio.h sys/xattr.h sys/bsdtty.h sys/event.h sys/file.h sys/ioctl.h \ sys/kern_control.h sys/loadavg.h sys/lock.h sys/mkdev.h sys/modem.h \ sys/param.h sys/random.h sys/select.h sys/sendfile.h sys/socket.h sys/statvfs.h \ sys/stat.h sys/syscall.h sys/sys_domain.h sys/termio.h sys/time.h \ -sys/times.h sys/types.h sys/uio.h sys/un.h sys/utsname.h sys/wait.h pty.h \ +sys/times.h sys/types.h sys/uio.h sys/un.h sys/utsname.h sys/wait.h pty.h utmp.h \ libutil.h sys/resource.h netpacket/packet.h sysexits.h bluetooth.h \ linux/tipc.h linux/random.h spawn.h util.h alloca.h endian.h \ sys/endian.h sys/sysmacros.h linux/memfd.h linux/wait.h sys/memfd.h \ @@ -14023,7 +14023,7 @@ fi -# check for openpty and forkpty +# check for openpty, login_tty, and forkpty for ac_func in openpty do : @@ -14119,6 +14119,103 @@ fi fi +fi +done + +for ac_func in login_tty +do : + ac_fn_c_check_func "$LINENO" "login_tty" "ac_cv_func_login_tty" +if test "x$ac_cv_func_login_tty" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_LOGIN_TTY 1 +_ACEOF + +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for login_tty in -lutil" >&5 +$as_echo_n "checking for login_tty in -lutil... " >&6; } +if ${ac_cv_lib_util_login_tty+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lutil $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char login_tty (); +int +main () +{ +return login_tty (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_util_login_tty=yes +else + ac_cv_lib_util_login_tty=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_util_login_tty" >&5 +$as_echo "$ac_cv_lib_util_login_tty" >&6; } +if test "x$ac_cv_lib_util_login_tty" = xyes; then : + $as_echo "#define HAVE_LOGIN_TTY 1" >>confdefs.h + LIBS="$LIBS -lutil" +else + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for login_tty in -lbsd" >&5 +$as_echo_n "checking for login_tty in -lbsd... " >&6; } +if ${ac_cv_lib_bsd_login_tty+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lbsd $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char login_tty (); +int +main () +{ +return login_tty (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_bsd_login_tty=yes +else + ac_cv_lib_bsd_login_tty=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_bsd_login_tty" >&5 +$as_echo "$ac_cv_lib_bsd_login_tty" >&6; } +if test "x$ac_cv_lib_bsd_login_tty" = xyes; then : + $as_echo "#define HAVE_LOGIN_TTY 1" >>confdefs.h + LIBS="$LIBS -lbsd" +fi + + +fi + + fi done diff --git a/configure.ac b/configure.ac index 754b066f52ed02..92a78ee3a1607f 100644 --- a/configure.ac +++ b/configure.ac @@ -2158,7 +2158,7 @@ sys/audioio.h sys/xattr.h sys/bsdtty.h sys/event.h sys/file.h sys/ioctl.h \ sys/kern_control.h sys/loadavg.h sys/lock.h sys/mkdev.h sys/modem.h \ sys/param.h sys/random.h sys/select.h sys/sendfile.h sys/socket.h sys/statvfs.h \ sys/stat.h sys/syscall.h sys/sys_domain.h sys/termio.h sys/time.h \ -sys/times.h sys/types.h sys/uio.h sys/un.h sys/utsname.h sys/wait.h pty.h \ +sys/times.h sys/types.h sys/uio.h sys/un.h sys/utsname.h sys/wait.h pty.h utmp.h \ libutil.h sys/resource.h netpacket/packet.h sysexits.h bluetooth.h \ linux/tipc.h linux/random.h spawn.h util.h alloca.h endian.h \ sys/endian.h sys/sysmacros.h linux/memfd.h linux/wait.h sys/memfd.h \ @@ -4081,7 +4081,7 @@ PY_CHECK_FUNC([setgroups], [ #endif ]) -# check for openpty and forkpty +# check for openpty, login_tty, and forkpty AC_CHECK_FUNCS(openpty,, AC_CHECK_LIB(util,openpty, @@ -4089,6 +4089,12 @@ AC_CHECK_FUNCS(openpty,, AC_CHECK_LIB(bsd,openpty, [AC_DEFINE(HAVE_OPENPTY) LIBS="$LIBS -lbsd"]) ) ) +AC_CHECK_FUNCS(login_tty,, + AC_CHECK_LIB(util,login_tty, + [AC_DEFINE(HAVE_LOGIN_TTY) LIBS="$LIBS -lutil"], + AC_CHECK_LIB(bsd,login_tty, [AC_DEFINE(HAVE_LOGIN_TTY) LIBS="$LIBS -lbsd"]) + ) +) AC_CHECK_FUNCS(forkpty,, AC_CHECK_LIB(util,forkpty, [AC_DEFINE(HAVE_FORKPTY) LIBS="$LIBS -lutil"], From d30e66b938a169289aa7ef5009574dc6b959bfea Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sat, 20 Nov 2021 10:10:38 +0000 Subject: [PATCH 02/13] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20b?= =?UTF-8?q?lurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NEWS.d/next/Library/2021-11-20-10-10-37.bpo-41818.mBTSEq.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2021-11-20-10-10-37.bpo-41818.mBTSEq.rst diff --git a/Misc/NEWS.d/next/Library/2021-11-20-10-10-37.bpo-41818.mBTSEq.rst b/Misc/NEWS.d/next/Library/2021-11-20-10-10-37.bpo-41818.mBTSEq.rst new file mode 100644 index 00000000000000..429af0a3175c14 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-11-20-10-10-37.bpo-41818.mBTSEq.rst @@ -0,0 +1 @@ +New function os.login_tty() for Unix. \ No newline at end of file From 1b02fd7e6ed92e70d0193579e2dfce7dc07df25d Mon Sep 17 00:00:00 2001 From: Soumendra Ganguly Date: Mon, 6 Dec 2021 14:12:50 -0600 Subject: [PATCH 03/13] Re-generate configure script using preferred version of autoconf. Signed-off-by: Soumendra Ganguly --- Modules/clinic/posixmodule.c.h | 2 +- Modules/posixmodule.c | 4 +-- configure | 63 ++++++++++++++++++++++++++++++++-- configure.ac | 9 ++--- pyconfig.h.in | 6 ++++ 5 files changed, 73 insertions(+), 11 deletions(-) diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index 8c6c93a03f69d1..98e365ef0c9072 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -9334,4 +9334,4 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ -/*[clinic end generated code: output=05505f171cdcff72 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=6afdc1313a84dee8 input=a9049054013a1b77]*/ diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index dd174a8c266145..fd587e7e436cd1 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -7212,9 +7212,9 @@ os_sched_getaffinity_impl(PyObject *module, pid_t pid) #endif #if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || defined(HAVE_LOGIN_TTY) || defined(HAVE_DEV_PTMX) -#if defined(HAVE_PTY_H) +#ifdef HAVE_PTY_H #include -#if defined(HAVE_UTMP_H) +#ifdef HAVE_UTMP_H #include #endif /* HAVE_UTMP_H */ #elif defined(HAVE_LIBUTIL_H) diff --git a/configure b/configure index 8582224dfd28f6..32da4d1fe6cb20 100755 --- a/configure +++ b/configure @@ -8467,7 +8467,7 @@ for ac_header in \ sys/random.h sys/resource.h sys/select.h sys/sendfile.h sys/socket.h sys/soundcard.h sys/stat.h \ sys/statvfs.h sys/sys_domain.h sys/syscall.h sys/sysmacros.h sys/termio.h sys/time.h sys/times.h \ sys/types.h sys/uio.h sys/un.h sys/utsname.h sys/wait.h sys/xattr.h sysexits.h syslog.h \ - termios.h util.h utime.h \ + termios.h util.h utime.h utmp.h \ do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` @@ -15757,7 +15757,7 @@ fi -# check for openpty and forkpty +# check for openpty, login_tty, and forkpty for ac_func in openpty do : @@ -15856,6 +15856,65 @@ fi fi done +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing login_tty" >&5 +$as_echo_n "checking for library containing login_tty... " >&6; } +if ${ac_cv_search_login_tty+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_func_search_save_LIBS=$LIBS +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char login_tty (); +int +main () +{ +return login_tty (); + ; + return 0; +} +_ACEOF +for ac_lib in '' util; do + if test -z "$ac_lib"; then + ac_res="none required" + else + ac_res=-l$ac_lib + LIBS="-l$ac_lib $ac_func_search_save_LIBS" + fi + if ac_fn_c_try_link "$LINENO"; then : + ac_cv_search_login_tty=$ac_res +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext + if ${ac_cv_search_login_tty+:} false; then : + break +fi +done +if ${ac_cv_search_login_tty+:} false; then : + +else + ac_cv_search_login_tty=no +fi +rm conftest.$ac_ext +LIBS=$ac_func_search_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_login_tty" >&5 +$as_echo "$ac_cv_search_login_tty" >&6; } +ac_res=$ac_cv_search_login_tty +if test "$ac_res" != no; then : + test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" + +$as_echo "#define HAVE_LOGIN_TTY 1" >>confdefs.h + + +fi + for ac_func in forkpty do : ac_fn_c_check_func "$LINENO" "forkpty" "ac_cv_func_forkpty" diff --git a/configure.ac b/configure.ac index 3585e5e73ab02e..ad40ed3a4bc3b3 100644 --- a/configure.ac +++ b/configure.ac @@ -2256,7 +2256,7 @@ AC_CHECK_HEADERS([ \ sys/random.h sys/resource.h sys/select.h sys/sendfile.h sys/socket.h sys/soundcard.h sys/stat.h \ sys/statvfs.h sys/sys_domain.h sys/syscall.h sys/sysmacros.h sys/termio.h sys/time.h sys/times.h \ sys/types.h sys/uio.h sys/un.h sys/utsname.h sys/wait.h sys/xattr.h sysexits.h syslog.h \ - termios.h util.h utime.h \ + termios.h util.h utime.h utmp.h \ ]) AC_HEADER_DIRENT AC_HEADER_MAJOR @@ -4315,11 +4315,8 @@ AC_CHECK_FUNCS(openpty,, AC_CHECK_LIB(bsd,openpty, [AC_DEFINE(HAVE_OPENPTY) LIBS="$LIBS -lbsd"]) ) ) -AC_CHECK_FUNCS(login_tty,, - AC_CHECK_LIB(util,login_tty, - [AC_DEFINE(HAVE_LOGIN_TTY) LIBS="$LIBS -lutil"], - AC_CHECK_LIB(bsd,login_tty, [AC_DEFINE(HAVE_LOGIN_TTY) LIBS="$LIBS -lbsd"]) - ) +AC_SEARCH_LIBS([login_tty], [util], + [AC_DEFINE([HAVE_LOGIN_TTY], [1], [Define to 1 if you have the `login_tty' function.])] ) AC_CHECK_FUNCS(forkpty,, AC_CHECK_LIB(util,forkpty, diff --git a/pyconfig.h.in b/pyconfig.h.in index c6cc1fd3777626..6a55d73017edfd 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -715,6 +715,9 @@ /* Define to 1 if you have the `log2' function. */ #undef HAVE_LOG2 +/* Define to 1 if you have the `login_tty' function. */ +#undef HAVE_LOGIN_TTY + /* Define to 1 if the system has the type `long double'. */ #undef HAVE_LONG_DOUBLE @@ -1374,6 +1377,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_UTIME_H +/* Define to 1 if you have the header file. */ +#undef HAVE_UTMP_H + /* Define to 1 if you have the `uuid_create' function. */ #undef HAVE_UUID_CREATE From 0f4d5b3c82f8dbc36acb9b8e15d6940d45b4d454 Mon Sep 17 00:00:00 2001 From: Soumendra Ganguly Date: Sat, 15 Jan 2022 21:37:43 -0600 Subject: [PATCH 04/13] Use #ifdef instead of #if defined() whenever possible. Signed-off-by: Soumendra Ganguly --- Modules/posixmodule.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index fd587e7e436cd1..4c23753cef55e0 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -7222,10 +7222,10 @@ os_sched_getaffinity_impl(PyObject *module, pid_t pid) #elif defined(HAVE_UTIL_H) #include #endif /* HAVE_PTY_H */ -#if defined(HAVE_STROPTS_H) +#ifdef HAVE_STROPTS_H #include #endif -#endif /* if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || defined(HAVE_LOGIN_TTY) || defined(HAVE_DEV_PTMX) */ +#endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || defined(HAVE_LOGIN_TTY) || defined(HAVE_DEV_PTMX) */ #if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX) @@ -7328,7 +7328,7 @@ os_openpty_impl(PyObject *module) #endif /* defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX) */ -#if defined(HAVE_SETSID) +#ifdef HAVE_SETSID #if defined(TIOCSCTTY) || defined(HAVE_TTYNAME) #define HAVE_FALLBACK_LOGIN_TTY 1 #endif /* defined(TIOCSCTTY) || defined(HAVE_TTYNAME) */ @@ -7352,7 +7352,7 @@ static PyObject * os_login_tty_impl(PyObject *module, int fd) /*[clinic end generated code: output=495a79911b4cc1bc input=5f298565099903a2]*/ { -#if defined(HAVE_LOGIN_TTY) +#ifdef HAVE_LOGIN_TTY if (login_tty(fd) == -1) { return posix_error(); } @@ -7363,7 +7363,7 @@ os_login_tty_impl(PyObject *module, int fd) } /* The tty becomes the controlling terminal. */ -#if defined(TIOCSCTTY) +#ifdef TIOCSCTTY if (ioctl(fd, TIOCSCTTY, (char *)NULL) == -1) { return posix_error(); } @@ -7393,7 +7393,7 @@ os_login_tty_impl(PyObject *module, int fd) return posix_error(); } close(tmpfd); -#endif /* defined(TIOCSCTTY) */ +#endif /* TIOCSCTTY */ /* The tty becomes stdin/stdout/stderr */ if (dup2(fd, 0) == -1 || dup2(fd, 1) == -1 || dup2(fd, 2) == -1) { @@ -7402,7 +7402,7 @@ os_login_tty_impl(PyObject *module, int fd) if (fd > 2) { close(fd); } -#endif /* defined(HAVE_LOGIN_TTY) */ +#endif /* HAVE_LOGIN_TTY */ Py_RETURN_NONE; } #endif /* defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY) */ From 7b27681db008c7df38b081f2d53ec4e9e093b771 Mon Sep 17 00:00:00 2001 From: Soumendra Ganguly Date: Mon, 17 Jan 2022 00:45:41 -0600 Subject: [PATCH 05/13] Copy posixmodule.c.h from branch 'main' to prepare to fix merge conflict Signed-off-by: Soumendra Ganguly --- Modules/clinic/posixmodule.c.h | 49 +++++++--------------------------- 1 file changed, 9 insertions(+), 40 deletions(-) diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index 98e365ef0c9072..282a5410f70206 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -1831,6 +1831,8 @@ os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *k #endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */ +#if defined(HAVE_UMASK) + PyDoc_STRVAR(os_umask__doc__, "umask($module, mask, /)\n" "--\n" @@ -1859,6 +1861,8 @@ os_umask(PyObject *module, PyObject *arg) return return_value; } +#endif /* defined(HAVE_UMASK) */ + PyDoc_STRVAR(os_unlink__doc__, "unlink($module, /, path, *, dir_fd=None)\n" "--\n" @@ -3102,41 +3106,6 @@ os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored)) #endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */ -#if (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) - -PyDoc_STRVAR(os_login_tty__doc__, -"login_tty($module, fd, /)\n" -"--\n" -"\n" -"Prepare the tty of which fd is a file descriptor for a new login session.\n" -"\n" -"Make the calling process a session leader; make the tty the\n" -"controlling tty, the stdin, the stdout, and the stderr of the\n" -"calling process; close fd."); - -#define OS_LOGIN_TTY_METHODDEF \ - {"login_tty", (PyCFunction)os_login_tty, METH_O, os_login_tty__doc__}, - -static PyObject * -os_login_tty_impl(PyObject *module, int fd); - -static PyObject * -os_login_tty(PyObject *module, PyObject *arg) -{ - PyObject *return_value = NULL; - int fd; - - if (!_PyLong_FileDescriptor_Converter(arg, &fd)) { - goto exit; - } - return_value = os_login_tty_impl(module, fd); - -exit: - return return_value; -} - -#endif /* (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) */ - #if defined(HAVE_FORKPTY) PyDoc_STRVAR(os_forkpty__doc__, @@ -8847,6 +8816,10 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na #define OS_SYSTEM_METHODDEF #endif /* !defined(OS_SYSTEM_METHODDEF) */ +#ifndef OS_UMASK_METHODDEF + #define OS_UMASK_METHODDEF +#endif /* !defined(OS_UMASK_METHODDEF) */ + #ifndef OS_UNAME_METHODDEF #define OS_UNAME_METHODDEF #endif /* !defined(OS_UNAME_METHODDEF) */ @@ -8931,10 +8904,6 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na #define OS_OPENPTY_METHODDEF #endif /* !defined(OS_OPENPTY_METHODDEF) */ -#ifndef OS_LOGIN_TTY_METHODDEF - #define OS_LOGIN_TTY_METHODDEF -#endif /* !defined(OS_LOGIN_TTY_METHODDEF) */ - #ifndef OS_FORKPTY_METHODDEF #define OS_FORKPTY_METHODDEF #endif /* !defined(OS_FORKPTY_METHODDEF) */ @@ -9334,4 +9303,4 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ -/*[clinic end generated code: output=6afdc1313a84dee8 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=d95ba7b0b9c52685 input=a9049054013a1b77]*/ From b8effd28862516c652fbdd8aa82b6bba94e83f4c Mon Sep 17 00:00:00 2001 From: Soumendra Ganguly Date: Mon, 17 Jan 2022 00:47:39 -0600 Subject: [PATCH 06/13] Generate posixmodule.c.h using argument clinic Signed-off-by: Soumendra Ganguly --- Modules/clinic/posixmodule.c.h | 41 +++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index 282a5410f70206..f399a37bf5b50c 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -3106,6 +3106,41 @@ os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored)) #endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */ +#if (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) + +PyDoc_STRVAR(os_login_tty__doc__, +"login_tty($module, fd, /)\n" +"--\n" +"\n" +"Prepare the tty of which fd is a file descriptor for a new login session.\n" +"\n" +"Make the calling process a session leader; make the tty the\n" +"controlling tty, the stdin, the stdout, and the stderr of the\n" +"calling process; close fd."); + +#define OS_LOGIN_TTY_METHODDEF \ + {"login_tty", (PyCFunction)os_login_tty, METH_O, os_login_tty__doc__}, + +static PyObject * +os_login_tty_impl(PyObject *module, int fd); + +static PyObject * +os_login_tty(PyObject *module, PyObject *arg) +{ + PyObject *return_value = NULL; + int fd; + + if (!_PyLong_FileDescriptor_Converter(arg, &fd)) { + goto exit; + } + return_value = os_login_tty_impl(module, fd); + +exit: + return return_value; +} + +#endif /* (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) */ + #if defined(HAVE_FORKPTY) PyDoc_STRVAR(os_forkpty__doc__, @@ -8904,6 +8939,10 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na #define OS_OPENPTY_METHODDEF #endif /* !defined(OS_OPENPTY_METHODDEF) */ +#ifndef OS_LOGIN_TTY_METHODDEF + #define OS_LOGIN_TTY_METHODDEF +#endif /* !defined(OS_LOGIN_TTY_METHODDEF) */ + #ifndef OS_FORKPTY_METHODDEF #define OS_FORKPTY_METHODDEF #endif /* !defined(OS_FORKPTY_METHODDEF) */ @@ -9303,4 +9342,4 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ -/*[clinic end generated code: output=d95ba7b0b9c52685 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=60c509fd80741877 input=a9049054013a1b77]*/ From 849229115d2d2ecf22bf5d2c998d34afc9a49df2 Mon Sep 17 00:00:00 2001 From: Soumendra Ganguly Date: Sun, 1 May 2022 21:47:22 -0500 Subject: [PATCH 07/13] Remove the archaic approach of opening a tty device file to make it the controlling terminal. --- Modules/posixmodule.c | 34 ++-------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 46f9588a633851..62e7370e5275e4 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -7378,11 +7378,9 @@ os_openpty_impl(PyObject *module) #endif /* defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX) */ -#ifdef HAVE_SETSID -#if defined(TIOCSCTTY) || defined(HAVE_TTYNAME) +#if defined(HAVE_SETSID) && defined(TIOCSCTTY) #define HAVE_FALLBACK_LOGIN_TTY 1 -#endif /* defined(TIOCSCTTY) || defined(HAVE_TTYNAME) */ -#endif /* HAVE_SETSID */ +#endif /* defined(HAVE_SETSID) && defined(TIOCSCTTY) */ #if defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY) /*[clinic input] @@ -7413,37 +7411,9 @@ os_login_tty_impl(PyObject *module, int fd) } /* The tty becomes the controlling terminal. */ -#ifdef TIOCSCTTY if (ioctl(fd, TIOCSCTTY, (char *)NULL) == -1) { return posix_error(); } -#else /* defined(HAVE_TTYNAME) */ - /* Fallback method (archaic); from Advanced Programming in the UNIX(R) - * Environment, Third edition, 2013, Section 9.6 - Controlling Terminal: - * "Systems derived from UNIX System V allocate the controlling - * terminal for a session when the session leader opens the first - * terminal device that is not already associated with a session, as - * long as the call to open does not specify the O_NOCTTY flag." */ - char *tmppath = ttyname(fd); - if (tmppath == NULL) { - return posix_error(); - } - -#define CLOSE_IF_NOT_FD(otherfd) \ - if (fd != otherfd) { \ - close(otherfd); \ - } \ - - CLOSE_IF_NOT_FD(0); - CLOSE_IF_NOT_FD(1); - CLOSE_IF_NOT_FD(2); - - int tmpfd = open(tmppath, O_RDWR); - if (tmpfd == -1) { - return posix_error(); - } - close(tmpfd); -#endif /* TIOCSCTTY */ /* The tty becomes stdin/stdout/stderr */ if (dup2(fd, 0) == -1 || dup2(fd, 1) == -1 || dup2(fd, 2) == -1) { From c3becc241fe704913bb428bc354aa8c2b891d4c4 Mon Sep 17 00:00:00 2001 From: Soumendra Ganguly Date: Sun, 1 May 2022 22:02:10 -0500 Subject: [PATCH 08/13] Resolve conflict in posixmodule.c.h --- Modules/clinic/posixmodule.c.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index f399a37bf5b50c..3f8b32f6ea9bc0 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -9342,4 +9342,4 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ -/*[clinic end generated code: output=60c509fd80741877 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=c8c5b148b96068b4 input=a9049054013a1b77]*/ From ec717f7f261b5ebff2d6a1e07041cf5a14af406b Mon Sep 17 00:00:00 2001 From: Soumendra Ganguly Date: Sun, 1 May 2022 22:25:14 -0500 Subject: [PATCH 09/13] Copy posixmodule.c.h from branch 'main' to prepare to fix merge conflict Signed-off-by: Soumendra Ganguly --- Modules/clinic/posixmodule.c.h | 93 +++++++++++++++------------------- 1 file changed, 41 insertions(+), 52 deletions(-) diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index 3f8b32f6ea9bc0..352dadc9b56270 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -3106,41 +3106,6 @@ os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored)) #endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */ -#if (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) - -PyDoc_STRVAR(os_login_tty__doc__, -"login_tty($module, fd, /)\n" -"--\n" -"\n" -"Prepare the tty of which fd is a file descriptor for a new login session.\n" -"\n" -"Make the calling process a session leader; make the tty the\n" -"controlling tty, the stdin, the stdout, and the stderr of the\n" -"calling process; close fd."); - -#define OS_LOGIN_TTY_METHODDEF \ - {"login_tty", (PyCFunction)os_login_tty, METH_O, os_login_tty__doc__}, - -static PyObject * -os_login_tty_impl(PyObject *module, int fd); - -static PyObject * -os_login_tty(PyObject *module, PyObject *arg) -{ - PyObject *return_value = NULL; - int fd; - - if (!_PyLong_FileDescriptor_Converter(arg, &fd)) { - goto exit; - } - return_value = os_login_tty_impl(module, fd); - -exit: - return return_value; -} - -#endif /* (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) */ - #if defined(HAVE_FORKPTY) PyDoc_STRVAR(os_forkpty__doc__, @@ -8325,12 +8290,10 @@ static PyObject * os_DirEntry_is_symlink(DirEntry *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; - static const char * const _keywords[] = { NULL}; - static _PyArg_Parser _parser = {":is_symlink", _keywords, 0}; int _return_value; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser - )) { + if (nargs) { + PyErr_SetString(PyExc_TypeError, "is_symlink() takes no arguments"); goto exit; } _return_value = os_DirEntry_is_symlink_impl(self, defining_class); @@ -8361,13 +8324,23 @@ os_DirEntry_stat(DirEntry *self, PyTypeObject *defining_class, PyObject *const * { PyObject *return_value = NULL; static const char * const _keywords[] = {"follow_symlinks", NULL}; - static _PyArg_Parser _parser = {"|$p:stat", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "stat", 0}; + PyObject *argsbuf[1]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; int follow_symlinks = 1; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &follow_symlinks)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { goto exit; } + if (!noptargs) { + goto skip_optional_kwonly; + } + follow_symlinks = PyObject_IsTrue(args[0]); + if (follow_symlinks < 0) { + goto exit; + } +skip_optional_kwonly: return_value = os_DirEntry_stat_impl(self, defining_class, follow_symlinks); exit: @@ -8392,14 +8365,24 @@ os_DirEntry_is_dir(DirEntry *self, PyTypeObject *defining_class, PyObject *const { PyObject *return_value = NULL; static const char * const _keywords[] = {"follow_symlinks", NULL}; - static _PyArg_Parser _parser = {"|$p:is_dir", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "is_dir", 0}; + PyObject *argsbuf[1]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; int follow_symlinks = 1; int _return_value; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &follow_symlinks)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { + goto exit; + } + if (!noptargs) { + goto skip_optional_kwonly; + } + follow_symlinks = PyObject_IsTrue(args[0]); + if (follow_symlinks < 0) { goto exit; } +skip_optional_kwonly: _return_value = os_DirEntry_is_dir_impl(self, defining_class, follow_symlinks); if ((_return_value == -1) && PyErr_Occurred()) { goto exit; @@ -8428,14 +8411,24 @@ os_DirEntry_is_file(DirEntry *self, PyTypeObject *defining_class, PyObject *cons { PyObject *return_value = NULL; static const char * const _keywords[] = {"follow_symlinks", NULL}; - static _PyArg_Parser _parser = {"|$p:is_file", _keywords, 0}; + static _PyArg_Parser _parser = {NULL, _keywords, "is_file", 0}; + PyObject *argsbuf[1]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; int follow_symlinks = 1; int _return_value; - if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, - &follow_symlinks)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); + if (!args) { + goto exit; + } + if (!noptargs) { + goto skip_optional_kwonly; + } + follow_symlinks = PyObject_IsTrue(args[0]); + if (follow_symlinks < 0) { goto exit; } +skip_optional_kwonly: _return_value = os_DirEntry_is_file_impl(self, defining_class, follow_symlinks); if ((_return_value == -1) && PyErr_Occurred()) { goto exit; @@ -8939,10 +8932,6 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na #define OS_OPENPTY_METHODDEF #endif /* !defined(OS_OPENPTY_METHODDEF) */ -#ifndef OS_LOGIN_TTY_METHODDEF - #define OS_LOGIN_TTY_METHODDEF -#endif /* !defined(OS_LOGIN_TTY_METHODDEF) */ - #ifndef OS_FORKPTY_METHODDEF #define OS_FORKPTY_METHODDEF #endif /* !defined(OS_FORKPTY_METHODDEF) */ From b2bcbc167f8010b434dad72098d237b372f86cf3 Mon Sep 17 00:00:00 2001 From: Soumendra Ganguly Date: Sun, 1 May 2022 22:28:28 -0500 Subject: [PATCH 10/13] Generate posixmodule.c.h using Argument Clinic Signed-off-by: Soumendra Ganguly --- Modules/clinic/posixmodule.c.h | 41 +++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index 352dadc9b56270..24eb39f726e8db 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -3106,6 +3106,41 @@ os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored)) #endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */ +#if (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) + +PyDoc_STRVAR(os_login_tty__doc__, +"login_tty($module, fd, /)\n" +"--\n" +"\n" +"Prepare the tty of which fd is a file descriptor for a new login session.\n" +"\n" +"Make the calling process a session leader; make the tty the\n" +"controlling tty, the stdin, the stdout, and the stderr of the\n" +"calling process; close fd."); + +#define OS_LOGIN_TTY_METHODDEF \ + {"login_tty", (PyCFunction)os_login_tty, METH_O, os_login_tty__doc__}, + +static PyObject * +os_login_tty_impl(PyObject *module, int fd); + +static PyObject * +os_login_tty(PyObject *module, PyObject *arg) +{ + PyObject *return_value = NULL; + int fd; + + if (!_PyLong_FileDescriptor_Converter(arg, &fd)) { + goto exit; + } + return_value = os_login_tty_impl(module, fd); + +exit: + return return_value; +} + +#endif /* (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) */ + #if defined(HAVE_FORKPTY) PyDoc_STRVAR(os_forkpty__doc__, @@ -8932,6 +8967,10 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na #define OS_OPENPTY_METHODDEF #endif /* !defined(OS_OPENPTY_METHODDEF) */ +#ifndef OS_LOGIN_TTY_METHODDEF + #define OS_LOGIN_TTY_METHODDEF +#endif /* !defined(OS_LOGIN_TTY_METHODDEF) */ + #ifndef OS_FORKPTY_METHODDEF #define OS_FORKPTY_METHODDEF #endif /* !defined(OS_FORKPTY_METHODDEF) */ @@ -9331,4 +9370,4 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ -/*[clinic end generated code: output=c8c5b148b96068b4 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=857242cad28f80b8 input=a9049054013a1b77]*/ From e35e7a04fde6d8ffdb3a3c371967de29b0a1723a Mon Sep 17 00:00:00 2001 From: Soumendra Ganguly Date: Sun, 1 May 2022 22:49:48 -0500 Subject: [PATCH 11/13] Remove the old news file. --- .../NEWS.d/next/Library/2021-11-20-10-10-37.bpo-41818.mBTSEq.rst | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Misc/NEWS.d/next/Library/2021-11-20-10-10-37.bpo-41818.mBTSEq.rst diff --git a/Misc/NEWS.d/next/Library/2021-11-20-10-10-37.bpo-41818.mBTSEq.rst b/Misc/NEWS.d/next/Library/2021-11-20-10-10-37.bpo-41818.mBTSEq.rst deleted file mode 100644 index 429af0a3175c14..00000000000000 --- a/Misc/NEWS.d/next/Library/2021-11-20-10-10-37.bpo-41818.mBTSEq.rst +++ /dev/null @@ -1 +0,0 @@ -New function os.login_tty() for Unix. \ No newline at end of file From 6a033b82094db150824ba1f32bce4217d0e5f919 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 2 May 2022 03:56:51 +0000 Subject: [PATCH 12/13] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20b?= =?UTF-8?q?lurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2022-05-02-03-56-50.gh-issue-85984.RBivvc.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2022-05-02-03-56-50.gh-issue-85984.RBivvc.rst diff --git a/Misc/NEWS.d/next/Library/2022-05-02-03-56-50.gh-issue-85984.RBivvc.rst b/Misc/NEWS.d/next/Library/2022-05-02-03-56-50.gh-issue-85984.RBivvc.rst new file mode 100644 index 00000000000000..e54f29ad2cbe53 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-05-02-03-56-50.gh-issue-85984.RBivvc.rst @@ -0,0 +1 @@ +New function os.login_tty() for Unix. From 5ad23a2f2f6d98cfd550bba759cb0c04f2c545ad Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith [Google LLC]" Date: Thu, 5 May 2022 03:25:24 +0000 Subject: [PATCH 13/13] fixup the argument clinic footer (regen) --- Modules/clinic/posixmodule.c.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index 60d45d2d1f862f..d62b09ed7406eb 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -9370,4 +9370,4 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ -/*[clinic end generated code: output=3b5a56add047ee1d input=a9049054013a1b77]*/ +/*[clinic end generated code: output=6150bcc25f5e4bc7 input=a9049054013a1b77]*/