-
Notifications
You must be signed in to change notification settings - Fork 251
Clean up lib/utmp.c and lib/logind.c #1290
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
base: master
Are you sure you want to change the base?
Clean up lib/utmp.c and lib/logind.c #1290
Conversation
77bf696
to
d847146
Compare
This comment was marked as resolved.
This comment was marked as resolved.
6e098e3
to
f4b0f37
Compare
29beffb
to
f124a09
Compare
69b1def
to
99d5669
Compare
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'd move interfaces to special headers, like "utmp_functions.h" and "logind_functions.h" and name functions differently, to avoid potential conflict.
This would also give you a freedom to use different prototypes: for example logind_active_sessions_count()
could have two parameters (without limit
), while utmp_active_sessions_count()
could have two parameters.
A third header "session_management.h" can include first two headers and route function calls to the real implementation.
For example:
#ifdef ENABLE_LOGIND
#define active_sessions_count(name, limit) logind_active_sessions_count(name)
#else
#define active_sessions_count(name, limit) utmp_active_sessions_count(name, limit)
#endif
This way you may skip some preprocessor macros in main code and get better optimisation even without LTO.
I'd like to have a look at that after the fixes to the build system. I'm not familiar with autotools, and this kind of thing will require some conditionals there, I guess. Let's do this round of refactors first, and then we'll see what else we can improve. |
a7f1ca1
to
2361b19
Compare
@ikerexxe , please have a look at this, so that it's easier for @Karlson2k to apply patches with a cleaner code. |
No problem. I can fix it easily later. |
2361b19
to
f6b6ec9
Compare
Those are for members that might be supported by some systems, but which are not supported on Linux. We need those checks, as otherwise it wouldn't build on Linux. And if we remove that code, we might be breaking shadow on those systems, by not updating properly their utmp entries. Our code will not stop building on systems if we remove code updating ut_syslen. It will just stop working correctly; but it will continue compiling there just fine. |
explicit_bzero(3) is available on glibc. |
Anyway, if the goal to support GNU/Linux only and you remove extra checks and use precisely what is (officially!) available on GNU/Linux, you will make code cleaner, simpler, easier to maintain and more secure. I'm talking about all the code, not only utmp interface part. At the same time you achieve build failure on unsupported systems automatically. That's my point. Removing support to be built without POSIX-optional member, which break compatibility even with POSIX, but keeping all other fields and interfaces as optional, while they are always available on GNU/Linux and mandatory by POSIX, and thus extending support beyond both POSIX and GNU/Linux, makes a very little sense. |
To be more specific. This change makes The configure and the C code still support other optional fields, like I'm suggesting to check in |
Is there any reason why glibc doesn't support those 2 fields that are present in NetBSD?
There are high chances that our code won't compile on NetBSD for other reasons. :)
I'm hesitant of doing that. If anyone wants to use this in NetBSD and is ready to send bug reports, I'd be happy to fix anything they find. Just like we're doing now for Hurd.
Agree; we should clear all unused fields. |
We're actually clearing them: Line 272 in 1f617f8
|
Most probably the historical reasons.
Yes, sure. Same for all other platforms. Why to keep compatibility with platforms that never tested and never used?
GNU Hurd is limited to the same libc libraries as GNU/Linux.
Just use |
We're using calloc(3) already. |
5a2eb4e
to
540e2db
Compare
540e2db
to
e0bdc49
Compare
e0bdc49
to
9578109
Compare
Signed-off-by: Alejandro Colomar <[email protected]>
libsystemd functions don't read the original contents of the second argument, and unconditionally set it on success. The NULL was unnecessary. The count initialization was always overwritten by assignment. Signed-off-by: Alejandro Colomar <[email protected]>
…h" header Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
This allows us using the [[gnu::malloc()]] attribute, by returning the newly allocated string. This is easier to use. Move the error code to errno, where it belongs. Signed-off-by: Alejandro Colomar <[email protected]>
…ote_host() This allows us using the [[gnu::malloc()]] attribute, by returning the newly allocated string. This is easier to use. Move the error code to errno, where it belongs. Signed-off-by: Alejandro Colomar <[email protected]>
glibc, musl libc, FreeBSD, NetBSD, and OpenBSD, all have ut_host. Signed-off-by: Alejandro Colomar <[email protected]>
This allows us using the [[gnu::malloc()]] attribute, and makes it easier to use. The error code is moved to errno, where it belongs. Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
This function already reports some errors, so it doesn't make sense to exit(3) on allocation error. We can report it just like any other error. Signed-off-by: Alejandro Colomar <[email protected]>
9578109
to
b0a2576
Compare
Cc: @Karlson2k , @ikerexxe
Revisions:
v2
v3
v4
#include "config.h"
with quotes. [@Karlson2k ]v5
v6
ut_host
exists.v7
v7b
v8
v8b
v8c