]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
terminal-util: drop support for pre-TIOCGPTPEER kernels
authorLennart Poettering <lennart@poettering.net>
Tue, 14 Jan 2025 11:05:05 +0000 (12:05 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 15 Jan 2025 09:39:04 +0000 (10:39 +0100)
Our minimum baseline is now far beyond 4.13, hence let's drop these
fallback paths.

README
src/basic/terminal-util.c
src/basic/terminal-util.h
src/machine/machine.c
src/run/run.c

diff --git a/README b/README
index 3aba52921a5bb435f55a050053d35c886c57edac..2480f10d5dc07fc60b28f131d347db930e36331c 100644 (file)
--- a/README
+++ b/README
@@ -37,6 +37,7 @@ REQUIREMENTS:
                      ≥ 4.9 for RENAME_NOREPLACE support in vfat
                      ≥ 4.10 for cgroup-bpf egress and ingress hooks
                      ≥ 4.11 for nsfs NS_GET_NSTYPE
+                     ≥ 4.13 for TIOCGPTPEER
                      ≥ 4.15 for cgroup-bpf device hook and cpu controller in cgroup v2
                      ≥ 4.17 for cgroup-bpf socket address hooks and /sys/power/resume_offset
                      ≥ 4.20 for PSI (used by systemd-oomd)
index b5dc3f21b877fb1dd036f6aad601d6d606442079..f1967a15c072473f4177452a4fc4197de4d0e6b7 100644 (file)
@@ -2324,7 +2324,7 @@ int terminal_is_pty_fd(int fd) {
         return true;
 }
 
-int pty_open_peer_racefree(int fd, int mode) {
+int pty_open_peer(int fd, int mode) {
         assert(fd >= 0);
 
         /* Opens the peer PTY using the new race-free TIOCGPTPEER ioctl() (kernel 4.13).
@@ -2339,9 +2339,6 @@ int pty_open_peer_racefree(int fd, int mode) {
                 if (peer_fd >= 0)
                         return peer_fd;
 
-                if (ERRNO_IS_IOCTL_NOT_SUPPORTED(errno)) /* new ioctl() is not supported, return a clear error */
-                        return -EOPNOTSUPP;
-
                 if (errno != EIO)
                         return -errno;
 
@@ -2352,31 +2349,3 @@ int pty_open_peer_racefree(int fd, int mode) {
                 (void) usleep_safe(50 * USEC_PER_MSEC);
         }
 }
-
-int pty_open_peer(int fd, int mode) {
-        int r;
-
-        assert(fd >= 0);
-
-        /* Opens the peer PTY using the new race-free TIOCGPTPEER ioctl() (kernel 4.13) if it is
-         * available. Otherwise falls back to the POSIX ptsname() + open() logic.
-         *
-         * Because of the fallback path this is not safe to be called on PTYs from other namespaces. (Because
-         * we open the peer PTY name there via a path in the file system.) */
-
-        // TODO: Remove fallback path once baseline is updated to >= 4.13, i.e. systemd v258
-
-        int peer_fd = pty_open_peer_racefree(fd, mode);
-        if (peer_fd >= 0)
-                return peer_fd;
-        if (!ERRNO_IS_NEG_NOT_SUPPORTED(peer_fd))
-                return peer_fd;
-
-        /* The racy fallback path */
-        _cleanup_free_ char *peer_path = NULL;
-        r = ptsname_malloc(fd, &peer_path);
-        if (r < 0)
-                return r;
-
-        return open_terminal(peer_path, mode);
-}
index 7ebfe61eb4f6f84cb589af650e73e96e9147bd57..a9c8ba7789d7e2abeb1a168131d34c68dcab2492 100644 (file)
@@ -165,7 +165,6 @@ int terminal_fix_size(int input_fd, int output_fd);
 
 int terminal_is_pty_fd(int fd);
 
-int pty_open_peer_racefree(int fd, int mode);
 int pty_open_peer(int fd, int mode);
 
 static inline bool osc_char_is_valid(char c) {
index 70714c30b48675633fd48ff97a9022459a6c18c4..3bb7a94ddd455c812b39a767ab27c1847c8a99b3 100644 (file)
@@ -805,13 +805,7 @@ int machine_start_shell(
         if (!p || !utmp_id)
                 return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "Path of pseudo TTY has unexpected prefix");
 
-        /* First try to get an fd for the PTY peer via the new racefree ioctl(), directly. Otherwise go via
-         * joining the namespace, because it goes by path */
-        pty_fd = pty_open_peer_racefree(ptmx_fd, O_RDWR|O_NOCTTY|O_CLOEXEC);
-        if (ERRNO_IS_NEG_NOT_SUPPORTED(pty_fd)) {
-                log_debug_errno(pty_fd, "Failed to get PTY peer via racefree ioctl() (ptmx_fd=%d). Trying via joining the namespace (ptmx_name=%s): %m", ptmx_fd, ptmx_name);
-                pty_fd = machine_open_terminal(m, ptmx_name, O_RDWR|O_NOCTTY|O_CLOEXEC);
-        }
+        pty_fd = pty_open_peer(ptmx_fd, O_RDWR|O_NOCTTY|O_CLOEXEC);
         if (pty_fd < 0)
                 return log_debug_errno(pty_fd, "Failed to open terminal: %m");
 
index 4a7a5d939c10d0b8a080a6f71f49096b5606ed18..3f7e0a6360b9b1ad456ee84a7ecb3ca15a631ba9 100644 (file)
@@ -1964,11 +1964,8 @@ static int start_transient_service(sd_bus *bus) {
                         if (!pty_path)
                                 return log_oom();
 
-                        peer_fd = pty_open_peer_racefree(pty_fd, O_RDWR|O_NOCTTY|O_CLOEXEC);
-                        if (ERRNO_IS_NEG_NOT_SUPPORTED(peer_fd))
-                                log_debug_errno(r, "TIOCGPTPEER ioctl not available, falling back to race-ful PTY peer opening: %m");
-                                /* We do not open the peer_fd in this case, we let systemd on the remote side open it instead */
-                        else if (peer_fd < 0)
+                        peer_fd = pty_open_peer(pty_fd, O_RDWR|O_NOCTTY|O_CLOEXEC);
+                        if (peer_fd < 0)
                                 return log_debug_errno(peer_fd, "Failed to open PTY peer: %m");
 
                         // FIXME: Introduce OpenMachinePTYEx() that accepts ownership/permission as param