-
Notifications
You must be signed in to change notification settings - Fork 254
Correct finding UTMP entry #1292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
3a3cc61 to
ebbdcb4
Compare
ebbdcb4 to
d00aba2
Compare
d00aba2 to
5cbab1f
Compare
|
PR has been updated to perform a minimal changes. Extra refactoring was excluded. |
5cbab1f to
bbf314f
Compare
85cd87a to
c8609da
Compare
c8609da to
7745204
Compare
|
@alejandro-colomar Rewritten again. |
7745204 to
2e7fc9c
Compare
|
Updated as requested (not counting extra getpid() call which is unsafe in terms of being future-proof). |
2e7fc9c to
7c972f6
Compare
|
Updated PR to fix only utmp entry search (align with Linux kernel description). |
ca8cb36 to
b5efd91
Compare
|
@alejandro-colomar Updated as requested, except this comment, for which the code is changed differently. |
Could you quote specific parts of utmp(5) to defend the correctness of your claims? Why is it valid to use an entry with matching PID but not matching ut_line? Why is it valid to use an entry matching the current terminal but not the PID? |
|
Here is (a shortened and a bit simplified) description of the process from https://man7.org/linux/man-pages/man5/utmp.5.html#DESCRIPTION:
Old version used entry only with both matches However, if user manually started |
b5efd91 to
ed21cd5
Compare
ed21cd5 to
a89cbfb
Compare
|
Let me know if any further changes are needed. |
ikerexxe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been trying to review this patch all week, but every time I started, something else caught my attention. Now I've had a good look at it, and I would say that the change in prepare_utmp() is incorrect. See the inline comment for more details.
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>
a89cbfb to
e8ae842
Compare
Nice catch, thanks! Corrected. |
ikerexxe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Good job!
|
@ikerexxe Thank you! |
This PR fixes wrong utmp entry search, by better following algorithm expected by Linux kernel as described here: https://man7.org/linux/man-pages/man5/utmp.5.html#DESCRIPTION