Re: [PATCH] query logind/elogind for number of users
"Craig Small" <[email protected]> ("csmall") Wed, 8 Mar 2023 22:59:17 +1100
| Newsgroups | gmane.linux.procps.devel |
|---|---|
| Message-ID | <CALy8Cw7-8pPx+=FPfe+96Hzw=iGmVOCjDFbESeHyJKT2de0DaQ@mail.gmail.com> |
--000000000000aac58705f66242e1 Content-Type: text/plain; charset="UTF-8" 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. 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! 4) What happens if you have the systemd libraries installed but not running systemd? 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 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? - Craig --000000000000aac58705f66242e1 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div dir=3D"ltr">On Tue, 7 Mar 2023 at 21:32, Thorsten Kuk= uk <<a href=3D"mailto:[email protected]">dmarc-noreply@freelis= ts.org</a>> wrote:<br></div><div class=3D"gmail_quote"><blockquote class= =3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rg= b(204,204,204);padding-left:1ex">libprocps uses utmp to count the number of= currently logged in users.<br> Since libprocps uses already libsystemd to get similar informations from<br= > logind/elogind, I propose the attached patch. This also solves the<br> issue, that, due to the fake entries, counting the users in utmp is not<br> reliable. E.g. xterm creates fake entries, GNOME does not. Same for e.g.<br= > screen and tmux, the first one creates fake entries, the second one not.<br= ></blockquote><div>Hi Thorsten,</div><div>=C2=A0 There are four points I= 9;d like to make.</div><div><br></div><div>1) If we are counting the users = and ignoring ut_tv then is the really a problem? Things that put utmp entri= es in will have an issue, but if we're counting the lines that would be= ok.</div><div><br></div><div>2) That being said, it makes sense on systems= that have systemd enabled to use that sd_get_sessions() call because it ge= ts around the fake/missing entries as you mentioned.</div><div><br></div><d= iv>3) Using the count getutent() method, the minimal is 0, with sd_get_sess= ions() you can go negative.</div><div>That means if there is some permissio= n issue and EACCESS is 13, you will see a utility print there are -13 users= !</div><div><br></div><div>=C2=A04) What happens if you have the systemd li= braries installed but not running systemd?</div><div><br></div><div>I thoug= ht that the compatibility mode wasn't set, surely they wouldn't use= that... but then saw on your technical page</div><div style=3D"margin-left= :40px">glibc defines <code>__WORDSIZE_TIME64_COMPAT32</code>,</div>Damn, so= close!</div><div class=3D"gmail_quote"><br></div><div class=3D"gmail_quote= "><div></div><div></div><blockquote class=3D"gmail_quote" style=3D"margin:0= px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> Comments?<br></blockquote><div>Maybe the idea is to call sd_get_sessions() = and if retval < 0 run the old code?</div><div>=C2=A0<br></div><blockquot= e class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px s= olid rgb(204,204,204);padding-left:1ex"> I know, w is also using utmp, one step after the other.<br></blockquote><di= v>And it is using the date fields too.</div><div><br></div><div>So in short= , how to handle non-systemd systems with libsystemd and errors?</div><div><= br></div><div>=C2=A0- Craig</div><div><br></div></div></div> --000000000000aac58705f66242e1--