shadow-maint / shadow

Upstream shadow tree
Other
305 stars 232 forks source link

`active_sessions_count()` #900

Closed alejandro-colomar closed 9 months ago

alejandro-colomar commented 9 months ago

https://github.com/shadow-maint/shadow/blob/4c0c7c52f14382f7b6f7e36337d28c4460923db4/lib/limits.c#L131

There are 2 definitions of this function, but only one call:

$ grep -rn active_sessions_count
lib/utmp.c:409:unsigned long active_sessions_count(const char *name, unsigned long limit)
lib/logind.c:39:unsigned long active_sessions_count(const char *name, unsigned long unused)
lib/limits.c:132:   count = active_sessions_count(name, limit);
lib/prototypes.h:505:extern unsigned long active_sessions_count(const char *name,
tests/unit/test_logind.c:36:static void test_active_sessions_count_return_ok(void **state)
tests/unit/test_logind.c:44:    count = active_sessions_count("testuser", 0);
tests/unit/test_logind.c:49:static void test_active_sessions_count_prefix_getpwnam_failure(void **state)
tests/unit/test_logind.c:56:    count = active_sessions_count("testuser", 0);
tests/unit/test_logind.c:64:        cmocka_unit_test(test_active_sessions_count_return_ok),
tests/unit/test_logind.c:65:        cmocka_unit_test(test_active_sessions_count_prefix_getpwnam_failure),

Do we build conditionally one or the other depending on the configuration, or is one of them dead code?

Cc: @ikerexxe

Iker, since you wrote tests for this function, do you know this?

ikerexxe commented 9 months ago

There are two implementations, one relies on utmp and the other on systemd. The first one is the old implementation, and we should be deprecating it at some point in the future. The second implementation is the present/future.