^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) .. SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) =====================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) The Devpts Filesystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) =====================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) Each mount of the devpts filesystem is now distinct such that ptys
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) and their indicies allocated in one mount are independent from ptys
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) and their indicies in all other mounts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) All mounts of the devpts filesystem now create a ``/dev/pts/ptmx`` node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) with permissions ``0000``.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) To retain backwards compatibility the a ptmx device node (aka any node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) created with ``mknod name c 5 2``) when opened will look for an instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) of devpts under the name ``pts`` in the same directory as the ptmx device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) As an option instead of placing a ``/dev/ptmx`` device node at ``/dev/ptmx``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) it is possible to place a symlink to ``/dev/pts/ptmx`` at ``/dev/ptmx`` or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) to bind mount ``/dev/ptx/ptmx`` to ``/dev/ptmx``. If you opt for using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) the devpts filesystem in this manner devpts should be mounted with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) the ``ptmxmode=0666``, or ``chmod 0666 /dev/pts/ptmx`` should be called.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) Total count of pty pairs in all instances is limited by sysctls::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) kernel.pty.max = 4096 - global limit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) kernel.pty.reserve = 1024 - reserved for filesystems mounted from the initial mount namespace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) kernel.pty.nr - current count of ptys
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) Per-instance limit could be set by adding mount option ``max=<count>``.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) This feature was added in kernel 3.4 together with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) ``sysctl kernel.pty.reserve``.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) In kernels older than 3.4 sysctl ``kernel.pty.max`` works as per-instance limit.