From 734c60ebb607086ad6d67b2544d6b7baba72a652 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Wed, 30 Jun 2021 07:21:14 +0200 Subject: login: Move libutil into libc The symbols forkpty, login, login_tty, logout, logwtmp, openpty were moved using scripts/move-symbol-to-libc.py. This is a single commit because most of the symbols are tied together via forkpty, for example. Several changes to use hidden prototypes are needed. This commit also updates pseudoterminal terminology on modified lines. For 390 (31-bit), this commit follows the existing style for the compat symbol version creation. Reviewed-by: Adhemerval Zanella --- login/Makefile | 15 +++++++++---- login/Versions | 19 +++++++++++++++- login/forkpty.c | 29 +++++++++++++++---------- login/libutil-compat.c | 33 ++++++++++++++++++++++++++++ login/login.c | 22 ++++++++++++------- login/login_tty.c | 32 ++++++++++++++++----------- login/logout.c | 19 +++++++++++----- login/logwtmp.c | 12 +++++++--- login/openpty.c | 59 +++++++++++++++++++++++++++----------------------- 9 files changed, 167 insertions(+), 73 deletions(-) create mode 100644 login/libutil-compat.c (limited to 'login') diff --git a/login/Makefile b/login/Makefile index bc72e6e..4e6b977 100644 --- a/login/Makefile +++ b/login/Makefile @@ -28,7 +28,7 @@ headers := utmp.h bits/utmp.h lastlog.h pty.h routines := getlogin getlogin_r setlogin getlogin_r_chk \ getutent getutent_r getutid getutline getutid_r getutline_r \ utmp_file utmpname updwtmp getpt grantpt unlockpt ptsname \ - ptsname_r_chk + ptsname_r_chk login login_tty logout logwtmp openpty forkpty CFLAGS-grantpt.c += -DLIBEXECDIR='"$(libexecdir)"' @@ -46,11 +46,18 @@ vpath %.c programs tests := tst-utmp tst-utmpx tst-grantpt tst-ptsname tst-getlogin tst-updwtmpx \ tst-pututxline-lockfail tst-pututxline-cache -# Build the -lutil library with these extra functions. +ifeq ($(have-GLIBC_2.33),yes) +# Empty compatibility library for old binaries. extra-libs := libutil extra-libs-others := $(extra-libs) - -libutil-routines:= login login_tty logout logwtmp openpty forkpty +libutil-routines := libutil-compat +libutil-shared-only-routines := libutil-compat + +# Pretend that libutil.so is a linker script, so that the symbolic +# link is not installed. +install-lib-ldscripts = libutil.so +$(inst_libdir)/libutil.so: +endif # $(have-GLIBC_2.33) include ../Rules diff --git a/login/Versions b/login/Versions index 475fcf0..b1ccf86 100644 --- a/login/Versions +++ b/login/Versions @@ -16,6 +16,14 @@ libc { # u* updwtmp; utmpname; + + # Symbols formerly in libutil. + forkpty; + login; + login_tty; + logout; + logwtmp; + openpty; } GLIBC_2.1 { # e* @@ -45,10 +53,19 @@ libc { __getlogin_r_chk; __ptsname_r_chk; } + GLIBC_2.34 { + # Symbols formerly in libutil. + forkpty; + login; + login_tty; + logout; + logwtmp; + openpty; + } } libutil { GLIBC_2.0 { - forkpty; login; login_tty; logout; logwtmp; openpty; + __libutil_version_placeholder; } } diff --git a/login/forkpty.c b/login/forkpty.c index 1e91bd8..79f9846 100644 --- a/login/forkpty.c +++ b/login/forkpty.c @@ -21,34 +21,41 @@ #include #include #include +#include int -forkpty (int *amaster, char *name, const struct termios *termp, - const struct winsize *winp) +__forkpty (int *pptmx, char *name, const struct termios *termp, + const struct winsize *winp) { - int master, slave, pid; + int ptmx, terminal, pid; - if (openpty (&master, &slave, name, termp, winp) == -1) + if (openpty (&ptmx, &terminal, name, termp, winp) == -1) return -1; - switch (pid = fork ()) + switch (pid = __fork ()) { case -1: - close (master); - close (slave); + __close (ptmx); + __close (terminal); return -1; case 0: /* Child. */ - close (master); - if (login_tty (slave)) + __close (ptmx); + if (login_tty (terminal)) _exit (1); return 0; default: /* Parent. */ - *amaster = master; - close (slave); + *pptmx = ptmx; + __close (terminal); return pid; } } +versioned_symbol (libc, __forkpty, forkpty, GLIBC_2_34); +libc_hidden_ver (__forkpty, forkpty) + +#if OTHER_SHLIB_COMPAT (libutil, GLIBC_2_0, GLIBC_2_34) +compat_symbol (libutil, __forkpty, forkpty, GLIBC_2_0); +#endif diff --git a/login/libutil-compat.c b/login/libutil-compat.c new file mode 100644 index 0000000..249512a --- /dev/null +++ b/login/libutil-compat.c @@ -0,0 +1,33 @@ +/* Placeholder compatibility symbols for libutil. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include + +/* This file is used to keep specific symbol versions occupied, so + that ld does not generate weak symbol version definitions. */ + +void +attribute_compat_text_section +__attribute_used__ +__libutil_version_placeholder_1 (void) +{ +} + +compat_symbol (libutil, __libutil_version_placeholder_1, + __libutil_version_placeholder, GLIBC_2_0); diff --git a/login/login.c b/login/login.c index d280c13..c95b984 100644 --- a/login/login.c +++ b/login/login.c @@ -23,7 +23,7 @@ #include #include #include - +#include /* Return the result of ttyname in the buffer pointed to by TTY, which should be of length BUF_LEN. If it is too long to fit in this buffer, a @@ -41,7 +41,7 @@ tty_name (int fd, char **tty, size_t buf_len) if (buf_len) { - rv = ttyname_r (fd, buf, buf_len); + rv = __ttyname_r (fd, buf, buf_len); if (rv != 0 || memchr (buf, '\0', buf_len)) /* We either got an error, or we succeeded and the @@ -78,7 +78,7 @@ tty_name (int fd, char **tty, size_t buf_len) } void -login (const struct utmp *ut) +__login (const struct utmp *ut) { #ifdef PATH_MAX char _tty[PATH_MAX + UT_LINESIZE]; @@ -114,16 +114,16 @@ login (const struct utmp *ut) strncpy (copy.ut_line, ttyp, UT_LINESIZE); /* Tell that we want to use the UTMP file. */ - if (utmpname (_PATH_UTMP) == 0) + if (__utmpname (_PATH_UTMP) == 0) { /* Open UTMP file. */ - setutent (); + __setutent (); /* Write the entry. */ - pututline (©); + __pututline (©); /* Close UTMP file. */ - endutent (); + __endutent (); } if (tty != _tty) @@ -135,5 +135,11 @@ login (const struct utmp *ut) strncpy (copy.ut_line, "???", UT_LINESIZE); /* Update the WTMP file. Here we have to add a new entry. */ - updwtmp (_PATH_WTMP, ©); + __updwtmp (_PATH_WTMP, ©); } +versioned_symbol (libc, __login, login, GLIBC_2_34); +libc_hidden_ver (__login, login) + +#if OTHER_SHLIB_COMPAT (libutil, GLIBC_2_0, GLIBC_2_34) +compat_symbol (libutil, __login, login, GLIBC_2_0); +#endif diff --git a/login/login_tty.c b/login/login_tty.c index a94f5cb..a85b388 100644 --- a/login/login_tty.c +++ b/login/login_tty.c @@ -37,13 +37,14 @@ static char sccsid[] = "@(#)login_tty.c 8.1 (Berkeley) 6/4/93"; #include #include #include +#include int -login_tty (int fd) +__login_tty (int fd) { - (void) setsid(); + __setsid(); #ifdef TIOCSCTTY - if (ioctl(fd, TIOCSCTTY, (char *)NULL) == -1) + if (__ioctl(fd, TIOCSCTTY, NULL) == -1) return (-1); #else { @@ -53,24 +54,29 @@ login_tty (int fd) if (fdname) { if (fd != 0) - (void) close (0); + _close (0); if (fd != 1) - (void) close (1); + __close (1); if (fd != 2) - (void) close (2); - newfd = open (fdname, O_RDWR); - (void) close (newfd); + __close (2); + newfd = __open64 (fdname, O_RDWR); + __close (newfd); } } #endif - while (dup2(fd, 0) == -1 && errno == EBUSY) + while (__dup2(fd, 0) == -1 && errno == EBUSY) ; - while (dup2(fd, 1) == -1 && errno == EBUSY) + while (__dup2(fd, 1) == -1 && errno == EBUSY) ; - while (dup2(fd, 2) == -1 && errno == EBUSY) + while (__dup2(fd, 2) == -1 && errno == EBUSY) ; if (fd > 2) - (void) close(fd); + __close(fd); return (0); } -libutil_hidden_def (login_tty) +versioned_symbol (libc, __login_tty, login_tty, GLIBC_2_34); +libc_hidden_ver (__login_tty, login_tty) + +#if OTHER_SHLIB_COMPAT (libutil, GLIBC_2_0, GLIBC_2_34) +compat_symbol (libutil, __login_tty, login_tty, GLIBC_2_0); +#endif diff --git a/login/logout.c b/login/logout.c index 3def97f..bf78e09 100644 --- a/login/logout.c +++ b/login/logout.c @@ -21,27 +21,28 @@ #include #include #include +#include int -logout (const char *line) +__logout (const char *line) { struct utmp tmp, utbuf; struct utmp *ut; int result = 0; /* Tell that we want to use the UTMP file. */ - if (utmpname (_PATH_UTMP) == -1) + if (__utmpname (_PATH_UTMP) == -1) return 0; /* Open UTMP file. */ - setutent (); + __setutent (); /* Fill in search information. */ tmp.ut_type = USER_PROCESS; strncpy (tmp.ut_line, line, sizeof tmp.ut_line); /* Read the record. */ - if (getutline_r (&tmp, &utbuf, &ut) >= 0) + if (__getutline_r (&tmp, &utbuf, &ut) >= 0) { /* Clear information about who & from where. */ memset (ut->ut_name, '\0', sizeof ut->ut_name); @@ -52,12 +53,18 @@ logout (const char *line) TIMESPEC_TO_TIMEVAL (&ut->ut_tv, &ts); ut->ut_type = DEAD_PROCESS; - if (pututline (ut) != NULL) + if (__pututline (ut) != NULL) result = 1; } /* Close UTMP file. */ - endutent (); + __endutent (); return result; } +versioned_symbol (libc, __logout, logout, GLIBC_2_34); +libc_hidden_ver (__logout, logout) + +#if OTHER_SHLIB_COMPAT (libutil, GLIBC_2_0, GLIBC_2_34) +compat_symbol (libutil, __logout, logout, GLIBC_2_0); +#endif diff --git a/login/logwtmp.c b/login/logwtmp.c index 1a7c46e..8f3e8fa 100644 --- a/login/logwtmp.c +++ b/login/logwtmp.c @@ -22,10 +22,10 @@ #include #include #include - +#include void -logwtmp (const char *line, const char *name, const char *host) +__logwtmp (const char *line, const char *name, const char *host) { struct utmp ut; @@ -41,5 +41,11 @@ logwtmp (const char *line, const char *name, const char *host) __clock_gettime64 (CLOCK_REALTIME, &ts); TIMESPEC_TO_TIMEVAL (&ut.ut_tv, &ts); - updwtmp (_PATH_WTMP, &ut); + __updwtmp (_PATH_WTMP, &ut); } +versioned_symbol (libc, __logwtmp, logwtmp, GLIBC_2_34); +libc_hidden_ver (__logwtmp, logwtmp) + +#if OTHER_SHLIB_COMPAT (libutil, GLIBC_2_0, GLIBC_2_34) +compat_symbol (libutil, __logwtmp, logwtmp, GLIBC_2_0); +#endif diff --git a/login/openpty.c b/login/openpty.c index 22845b6..1527757 100644 --- a/login/openpty.c +++ b/login/openpty.c @@ -25,7 +25,7 @@ #include #include #include - +#include /* Return the result of ptsname_r in the buffer pointed to by PTS, which should be of length BUF_LEN. If it is too long to fit in @@ -43,7 +43,7 @@ pts_name (int fd, char **pts, size_t buf_len) if (buf_len) { - rv = ptsname_r (fd, buf, buf_len); + rv = __ptsname_r (fd, buf, buf_len); if (rv != 0 || memchr (buf, '\0', buf_len)) /* We either got an error, or we succeeded and the @@ -79,12 +79,12 @@ pts_name (int fd, char **pts, size_t buf_len) return rv; } -/* Create pseudo tty master slave pair and set terminal attributes +/* Create pseudo tty multiplexer/terminal pair and set terminal attributes according to TERMP and WINP. Return handles for both ends in - AMASTER and ASLAVE, and return the name of the slave end in NAME. */ + *PPTMX and *PTERMINAL, and return the name of the terminal end in NAME. */ int -openpty (int *amaster, int *aslave, char *name, - const struct termios *termp, const struct winsize *winp) +__openpty (int *pptmx, int *pterminal, char *name, + const struct termios *termp, const struct winsize *winp) { #ifdef PATH_MAX char _buf[PATH_MAX]; @@ -92,51 +92,51 @@ openpty (int *amaster, int *aslave, char *name, char _buf[512]; #endif char *buf = _buf; - int master, ret = -1, slave = -1; + int ptmx, ret = -1, terminal = -1; *buf = '\0'; - master = getpt (); - if (master == -1) + ptmx = __getpt (); + if (ptmx == -1) return -1; - if (grantpt (master)) + if (grantpt (ptmx)) goto on_error; - if (unlockpt (master)) + if (unlockpt (ptmx)) goto on_error; #ifdef TIOCGPTPEER - /* Try to allocate slave fd solely based on master fd first. */ - slave = ioctl (master, TIOCGPTPEER, O_RDWR | O_NOCTTY); + /* Try to allocate terminal fd solely based on PTMX fd first. */ + terminal = __ioctl (ptmx, TIOCGPTPEER, O_RDWR | O_NOCTTY); #endif - if (slave == -1) + if (terminal == -1) { - /* Fallback to path-based slave fd allocation in case kernel doesn't + /* Fallback to path-based terminal fd allocation in case kernel doesn't * support TIOCGPTPEER. */ - if (pts_name (master, &buf, sizeof (_buf))) + if (pts_name (ptmx, &buf, sizeof (_buf))) goto on_error; - slave = open (buf, O_RDWR | O_NOCTTY); - if (slave == -1) + terminal = __open64 (buf, O_RDWR | O_NOCTTY); + if (terminal == -1) goto on_error; } /* XXX Should we ignore errors here? */ if (termp) - tcsetattr (slave, TCSAFLUSH, termp); + tcsetattr (terminal, TCSAFLUSH, termp); #ifdef TIOCSWINSZ if (winp) - ioctl (slave, TIOCSWINSZ, winp); + __ioctl (terminal, TIOCSWINSZ, winp); #endif - *amaster = master; - *aslave = slave; + *pptmx = ptmx; + *pterminal = terminal; if (name != NULL) { if (*buf == '\0') - if (pts_name (master, &buf, sizeof (_buf))) + if (pts_name (ptmx, &buf, sizeof (_buf))) goto on_error; strcpy (name, buf); @@ -146,10 +146,10 @@ openpty (int *amaster, int *aslave, char *name, on_error: if (ret == -1) { - close (master); + __close (ptmx); - if (slave != -1) - close (slave); + if (terminal != -1) + __close (terminal); } if (buf != _buf) @@ -157,4 +157,9 @@ openpty (int *amaster, int *aslave, char *name, return ret; } -libutil_hidden_def (openpty) +versioned_symbol (libc, __openpty, openpty, GLIBC_2_34); +libc_hidden_ver (__openpty, openpty) + +#if OTHER_SHLIB_COMPAT (libutil, GLIBC_2_0, GLIBC_2_34) +compat_symbol (libutil, __openpty, openpty, GLIBC_2_0); +#endif -- cgit v1.1