GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-41818: Add os.login_tty() for *nix. by 8vasu · Pull Request #29658 · python/cpython

bpo-41818: Add os.login_tty() for *nix. #29658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
gpshead merged 17 commits into python:main from 8vasu:login_tty
May 5, 2022

Uh oh!

There was an error while loading. Please reload this page.

Merged

bpo-41818: Add os.login_tty() for *nix. #29658

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
576bc5a
Add os.login_tty() for Unix.
8vasu Nov 20, 2021
d30e66b
📜🤖 Added by blurb_it.
blurb-it[bot] Nov 20, 2021
089cb17
Merge branch 'main' into login_tty
tiran Dec 4, 2021
1b02fd7
Re-generate configure script using preferred version of autoconf.
8vasu Dec 6, 2021
0f4d5b3
Use #ifdef instead of #if defined() whenever possible.
8vasu Jan 16, 2022
7b27681
Copy posixmodule.c.h from branch 'main' to prepare to fix merge conflict
8vasu Jan 17, 2022
f5b28a0
Merge branch 'main' into login_tty
8vasu Jan 17, 2022
b8effd2
Generate posixmodule.c.h using argument clinic
8vasu Jan 17, 2022
8492291
Remove the archaic approach of opening a tty device file to make it t…
8vasu May 2, 2022
c3becc2
Resolve conflict in posixmodule.c.h
8vasu May 2, 2022
ec717f7
Copy posixmodule.c.h from branch 'main' to prepare to fix merge conflict
8vasu May 2, 2022
995746e
Merge branch 'main' into login_tty
8vasu May 2, 2022
b2bcbc1
Generate posixmodule.c.h using Argument Clinic
8vasu May 2, 2022
e35e7a0
Remove the old news file.
8vasu May 2, 2022
6a033b8
📜🤖 Added by blurb_it.
blurb-it[bot] May 2, 2022
dc69763
Merge branch 'main' into login_tty
gpshead May 5, 2022
5ad23a2
fixup the argument clinic footer (regen)
gpshead May 5, 2022
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

11 changes: 11 additions & 0 deletions 11 Doc/library/os.rst
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,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
Expand Down
1 change: 1 addition & 0 deletions 1 Misc/NEWS.d/next/Library/2022-05-02-03-56-50.gh-issue-85984.RBivvc.rst
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
New function os.login_tty() for Unix.
41 changes: 40 additions & 1 deletion 41 Modules/clinic/posixmodule.c.h
Show comments
View file
Open in desktop

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

69 changes: 60 additions & 9 deletions 69 Modules/posixmodule.c
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -7274,22 +7274,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)
#if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || defined(HAVE_LOGIN_TTY) || defined(HAVE_DEV_PTMX)
#ifdef HAVE_PTY_H
#include <pty.h>
#else
#ifdef HAVE_LIBUTIL_H
#ifdef HAVE_UTMP_H
#include <utmp.h>
#endif /* HAVE_UTMP_H */
#elif defined(HAVE_LIBUTIL_H)
#include <libutil.h>
#else
#ifdef HAVE_UTIL_H
#elif defined(HAVE_UTIL_H)
#include <util.h>
#endif /* HAVE_UTIL_H */
#endif /* HAVE_LIBUTIL_H */
#endif /* HAVE_PTY_H */
#ifdef HAVE_STROPTS_H
#include <stropts.h>
#endif
#endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || 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)
Expand Down Expand Up @@ -7392,6 +7391,56 @@ os_openpty_impl(PyObject *module)
#endif /* defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX) */


#if defined(HAVE_SETSID) && defined(TIOCSCTTY)
#define HAVE_FALLBACK_LOGIN_TTY 1
#endif /* defined(HAVE_SETSID) && defined(TIOCSCTTY) */

#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]*/
{
#ifdef 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 (ioctl(fd, TIOCSCTTY, (char *)NULL) == -1) {
return posix_error();
}

/* The tty becomes stdin/stdout/stderr */
if (dup2(fd, 0) == -1 || dup2(fd, 1) == -1 || dup2(fd, 2) == -1) {
return posix_error();
Comment thread
gpshead marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

}
if (fd > 2) {
close(fd);
}
#endif /* HAVE_LOGIN_TTY */
Py_RETURN_NONE;
}
#endif /* defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY) */


#ifdef HAVE_FORKPTY
/*[clinic input]
os.forkpty
Expand Down Expand Up @@ -7427,8 +7476,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 */
Expand Down Expand Up @@ -14797,6 +14847,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
Expand Down
63 changes: 61 additions & 2 deletions 63 configure
Show comments
View file
Open in desktop

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

7 changes: 5 additions & 2 deletions 7 configure.ac
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2508,7 +2508,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
Expand Down Expand Up @@ -4670,14 +4670,17 @@ 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,
[AC_DEFINE(HAVE_OPENPTY) LIBS="$LIBS -lutil"],
AC_CHECK_LIB(bsd,openpty, [AC_DEFINE(HAVE_OPENPTY) 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,
[AC_DEFINE(HAVE_FORKPTY) LIBS="$LIBS -lutil"],
Expand Down
6 changes: 6 additions & 0 deletions 6 pyconfig.h.in
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,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

Expand Down Expand Up @@ -1389,6 +1392,9 @@
/* Define to 1 if you have the <utime.h> header file. */
#undef HAVE_UTIME_H

/* Define to 1 if you have the <utmp.h> header file. */
#undef HAVE_UTMP_H

/* Define to 1 if you have the `uuid_create' function. */
#undef HAVE_UUID_CREATE

Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.