• Michal Sekletar's avatar
    tty: tty_io: update timestamps on all device nodes · 360c11e2
    Michal Sekletar authored
    User space applications watch for timestamp changes on character device
    files in order to determine idle time of a given terminal session. For
    example, "w" program uses this information to populate the IDLE column
    of its output [1]. Similarly, systemd-logind has optional feature where
    it uses atime of the tty character device to determine if there was
    activity on the terminal associated with the logind's session object. If
    there was no activity for a configured period of time then logind will
    terminate such session [2].
    
    Now, usually (e.g. bash running on the terminal) the use of the terminal
    will update timestamps (atime and mtime) on the corresponding terminal
    character device. However, if access to the terminal, e.g. /dev/pts/0,
    is performed through magic character device /dev/tty then such access
    obviously changes the state of the terminal, however timestamps on the
    device that correspond to the terminal (/dev/pts/0) are not updated.
    
    This patch makes sure that we update timestamps on *all* character
    devices that correspond to the given tty, because outside observers (w,
    systemd-logind) are maybe checking these timestamps. Obviously, they can
    not check timestamps on /dev/tty as that has per-process meaning.
    
    [1] https://gitlab.com/procps-ng/procps/-/blob/v4.0.0/w.c#L286
    [2] https://github.com/systemd/systemd/blob/v252/NEWS#L477
    
    Signed-off-by: default avatarMichal Sekletar <msekleta@redhat.com>
    Message-ID: <20230613172107.78138-1-msekleta@redhat.com>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    360c11e2
tty_io.c 89.5 KB