-
Notifications
You must be signed in to change notification settings - Fork 256
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
Karlson2k
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'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)
#endifThis 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
We're using calloc(3) already. |
5a2eb4e to
540e2db
Compare
540e2db to
e0bdc49
Compare
e0bdc49 to
9578109
Compare
9578109 to
b0a2576
Compare
b0a2576 to
068b363
Compare
068b363 to
df67d51
Compare
df67d51 to
92b948d
Compare
92b948d to
915a86c
Compare
d74433a to
0b19168
Compare
0b19168 to
90d1432
Compare
Signed-off-by: Alejandro Colomar <alx@kernel.org>
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 <alx@kernel.org>
…h" header Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
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 <alx@kernel.org>
…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 <alx@kernel.org>
glibc, musl libc, FreeBSD, NetBSD, and OpenBSD, all have ut_host. Signed-off-by: Alejandro Colomar <alx@kernel.org>
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 <alx@kernel.org>
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 <alx@kernel.org>
90d1432 to
1a6a0ee
Compare
Cc: @Karlson2k , @ikerexxe
Revisions:
v2
v3
v4
#include "config.h"with quotes. [@Karlson2k ]v5
v6
ut_hostexists.v7
v7b
v8
v8b
v8c
v8d
v8e
v8f
v9
v9b
v9c
v9d
v9e