src/usermod.c: Some cleanups, improvements, fixes, and abstractions about open/close/lock/unlock on database files#1590
Conversation
Fix white space. Signed-off-by: Alejandro Colomar <alx@kernel.org>
If we're here, 'is_shadow_pwd' is true. See the enclosing conditional. Fixes: 1e0f529 (2026-03-17; "usermod: only lock shadow file as needed") Cc: Pat Riehecky <riehecky@fnal.gov> Signed-off-by: Alejandro Colomar <alx@kernel.org>
Fixes: 24e742d (2007-11-17; "* src/usermod.c (fail_exit): Add static variables pw_locked,...") Cc: Pat Riehecky <riehecky@fnal.gov> Signed-off-by: Alejandro Colomar <alx@kernel.org>
Fixes: e65380f (2026-03-17; "usermod: only unlock on close_files if we actually locked them") Cc: Pat Riehecky <riehecky@fnal.gov> Signed-off-by: Alejandro Colomar <alx@kernel.org>
We only care about sgr_locked for closing&unlocking gshadow. Fixes: e65380f (2026-03-17; "usermod: only unlock on close_files if we actually locked them") Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This is unnecessary here, but it will help splitting this code into a library function. Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
It closes and unlocks, but doesn't fail_exit(). Instead, it reports an error code. Signed-off-by: Alejandro Colomar <alx@kernel.org>
This is simpler, as we can re-use unlock_db(). Signed-off-by: Alejandro Colomar <alx@kernel.org>
|
@jcpunk , @stoeckmann , since you've recently looked at this code, it'd be good if you could review this PR. The functions |
28b871b to
3648787
Compare
jcpunk
left a comment
There was a problem hiding this comment.
The bits I understand all look good to me.
|
Should there be a top level |
I'm not yet convinced about it. But I'll experiment with it. |
This prepares for the following commit. Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
I've been experimenting with it, and found it to be terrible. (Maybe I just don't know how to use it correctly?) I'd like to enforce a few style things, but clang-format(1) seems too strict. Is there a way to tell clang-format(1) "I want to fix spaces between a function and its It seems clang-format(1) is indeed as terrible as it seems: |
|
For just space removal, I whipped up a few quick |
Looks good to me. With these error handlings in |
I wouldn't call it terrible. It's just not designed for performing incremental steps. One project under clang-format governance is https://github.com/kmod-project/kmod (and yes, I really mean governance if it's in place ...) You can specify exceptions in files if you disagree with the format, but otherwise it comes in handy as a guard for incoming pull requests and is a one-liner to call. |
|
On the other hand, I also know glib (and thus GNOME as a whole) and their rule is to only properly format a line which is already modified due to a PR. This in turn means that it'll never have any finished code style in it ... ;) But blaming code lines is way more meaningful this way, after all you are not annoyed with "I have fixed the code style" annotations. |
|
My reading of https://git-scm.com/docs/git-blame suggests a file could be used to ignore specific commits for git blame. |
Thanks!
I hadn't thought about it, but we could do it. But then fail_exit() should either be part of the library, or it should close_db() instead of unlock_db(). Any opinion on that? |
Oh, right. We need it to avoid actually writing out data in case of error. Then it's part of the API. |
The problem is a bit more complex than that. Most rules should have exceptions, which humans with good taste could choose to apply. Such a strict automation isn't able to do that. And some rules should be more fine grained: for example, I like indenting function calls after the Instead, a good design of a tool would recognize that it has limitations, and it should allow specifying that one doesn't want to apply a rule in any currently implemented ways.
The thing is I don't want exceptions by file, but by rule. |
I think that's a bad idea. Such commits could introduce bugs accidentally, so git-blame(1) should show everything. I prefer ignoring them in my head. Tools should not ignore them. |
This is a cleanup before starting to work on moving this to lib/ and using it everywhere.
Cc: @jcpunk, @stoeckmann
Revisions:
v2