]> git.ipfire.org Git - thirdparty/shadow.git/commit
lib/utmp.c: Fix umtp entry search
authorEvgeny Grin (Karlson2k) <k2k@drgrin.dev>
Mon, 14 Jul 2025 19:37:08 +0000 (21:37 +0200)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Sat, 9 Aug 2025 09:18:51 +0000 (11:18 +0200)
commit841776561f56bae7382c6bd47e428201a155d39c
tree074c3e431680ef36ea5515228d019a45d26ae8f9
parentc1678a9e2759f60a2daf5e136c76fa6e47d6f400
lib/utmp.c: Fix umtp entry search

Updated utmp entry search algorithm to follow GNU/Linux description:
https://man7.org/linux/man-pages/man5/utmp.5.html#DESCRIPTION

An entry is found by looking for matching PID.  If several such entries
found (for example, due to cleanup failure of old entries) then first
entry with both matching PID and matching 'ut_line' (current terminal)
is used.  If not entry has matching 'ut_line' then first entry with
matching PID is used (if getty/init process does not set 'ut_line').

When no single entry is matched by PID, then but at least one entry is
matched current terminal the the first such entry is selected (if getty
does not set correct PID).

This commit uses non-portable Elvis operator is it is already used
everywhere in the code.

Signed-off-by: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
lib/utmp.c