Skip to content

Conversation

@alejandro-colomar
Copy link
Collaborator

@alejandro-colomar alejandro-colomar commented Dec 12, 2025

Some readability improvements around wtmp(5).

Closes: #1415


Revisions:

v1b
  • Rebase
$ git rd 
1:  b01e53f0e = 1:  f65be2147 lib/utmp.c: Reword comment
2:  6e1602679 = 2:  1b5294fd2 lib/utmp.c: Move assertion out of setutmp()
3:  8f797ecf7 = 3:  4374ff4b1 lib/utmp.c: Move updwtmpx(3) call out of setutmp()
4:  aec39c45b = 4:  3c2627d63 lib/utmp.c: setutmp(): Simplify error handling
5:  7775c9753 = 5:  53c221c1d lib/utmp.c: Rename setutmp() => updutmpx()
6:  7c1543e10 = 6:  d67a08960 lib/utmp*: Move wtmp(5) APIs to "utmp/wtmp.h"
7:  be6b6a984 = 7:  1753b65fc lib/utmp/wtmp.*: updwtmpx(): Cosmetic
v1c
  • Rebase
$ git rd 
1:  f65be2147 = 1:  f6d6f97a1 lib/utmp.c: Reword comment
2:  1b5294fd2 = 2:  5c41f4b47 lib/utmp.c: Move assertion out of setutmp()
3:  4374ff4b1 = 3:  5e58315b6 lib/utmp.c: Move updwtmpx(3) call out of setutmp()
4:  3c2627d63 = 4:  87ba0c851 lib/utmp.c: setutmp(): Simplify error handling
5:  53c221c1d = 5:  fab57f3a7 lib/utmp.c: Rename setutmp() => updutmpx()
6:  d67a08960 = 6:  b0f777b17 lib/utmp*: Move wtmp(5) APIs to "utmp/wtmp.h"
7:  1753b65fc = 7:  b92c8c4e4 lib/utmp/wtmp.*: updwtmpx(): Cosmetic

Closes: <shadow-maint#1415>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
What we really wanted to assert is that prepare_utmp() hasn't failed.

This way, the intent is more readable, and it will allow us to do some
refactoring.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
This separates wtmp(5) handling from utmp(5) handling, which itself
allows removing comments.  This results in obviously more readable code.

Now, setutmp() resembles updwtmpx(3), so we could name it to updutmpx().

Before this change, we updated first utmp(5), then wtmp(5).  This change
reoders them, as the order does not matter (they are completely
independent).  This is because updwtmpx(3) cannot fail, while our
updating of utmp(5) can fail.  With this ordering, we'll be able to
report errors, while at the same time we make sure to update wtmp(5)
even if utmp(5) fails.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This is for consistency with updwtmpx(3), which is very similar to this
function, with the following exceptions:

-  updutmpx() can fail, while updwtmpx(3) can't fail.
-  updutmpx() doesn't take a pathname.  This is because utmp(5) APIs
   rely on utmpname(3) for specifying the path of the utmp(5) file (and
   use _PATH_UTMP if it is not called).

Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Minor cosmetic adjestments.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Simpler A good issue for a new beginner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misterious comment.

1 participant