≥ 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)
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).
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;
(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);
-}
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) {
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");
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