Re: [PATCH] query logind/elogind for number of users
"Thorsten Kukuk" <[email protected]> ("kukuk") Wed, 8 Mar 2023 14:48:50 +0100
| Newsgroups | gmane.linux.procps.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi Craig, On Wed, Mar 08, Craig Small wrote: > On Tue, 7 Mar 2023 at 21:32, Thorsten Kukuk <[email protected]> > wrote: > > libprocps uses utmp to count the number of currently logged in users. > Since libprocps uses already libsystemd to get similar informations from > logind/elogind, I propose the attached patch. This also solves the > issue, that, due to the fake entries, counting the users in utmp is not > reliable. E.g. xterm creates fake entries, GNOME does not. Same for e.g. > screen and tmux, the first one creates fake entries, the second one not. > > Hi Thorsten, > There are four points I'd like to make. > > 1) If we are counting the users and ignoring ut_tv then is the really a > problem? Things that put utmp entries in will have an issue, but if we're > counting the lines that would be ok. There are two problems: 1. long or short term glibc developers want to deprecate and remove the utmp/wtmp/lastlog interfaces from glibc because they say it's legacy, the Y2038 problem is not fixable inside glibc and the DoS problem with utmp is not solveable inside glibc, too. I don't know when this will happen. But the big Linux distributions are preparing now their distributions which will be longer maintained and supported then 2038, so they need something which does not depend on the current utmp format in the near future. 2. the number of utmp entries does not tell you anything about how many users are logged in. As explained in my blog: Use GNOME or XFCE with many terminals and utmp will have exactly one entry. Use KDE or X11/xterm with many terminals and you will have 1+number of terminals utmp entries. So if there is an alternative, which provides the needed features in a more realible way not depending on utmp, I would prefer that. > 2) That being said, it makes sense on systems that have systemd enabled to use > that sd_get_sessions() call because it gets around the fake/missing entries as > you mentioned. > > 3) Using the count getutent() method, the minimal is 0, with sd_get_sessions() > you can go negative. > That means if there is some permission issue and EACCESS is 13, you will see a > utility print there are -13 users! You are right, even if I don't think this will happen. But what would be a good way to report an error? utmp would just don't return any utmp entries, which leads to a wrong "0 users" message. So the problem exists already today, but in a way that a user wouldn't even notice it. > 4) What happens if you have the systemd libraries installed but not running > systemd? I don't know and I don't think that anybody would compile/link an application with systemd support without using systemd. Linux distributors would not do that. People building their own distribution wouldn't do that, too. Other applications making more heavy use of libsystemd do just fail. > I thought that the compatibility mode wasn't set, surely they wouldn't use > that... but then saw on your technical page > glibc defines __WORDSIZE_TIME64_COMPAT32, > Damn, so close! > > > Comments? > > Maybe the idea is to call sd_get_sessions() and if retval < 0 run the old code? I can change the code that way, shouldn't be a problem if really wanted. > > I know, w is also using utmp, one step after the other. > > And it is using the date fields too. > > So in short, how to handle non-systemd systems with libsystemd and errors? I can only say what other utilities do: if you compile them with systemd support, they require systemd to be running to work correct. Since libprocps uses already libsystemd: how do the other functions behave in this case? Thorsten -- Thorsten Kukuk, Distinguished Engineer, Senior Architect, Future Technologies SUSE Software Solutions Germany GmbH, Frankenstraße 146, 90461 Nuernberg, Germany Managing Director: Ivo Totev, Andrew Myers, Andrew McDonald, Martje Boudien Moerman (HRB 36809, AG Nürnberg)