Re: [PATCH] query logind/elogind for number of users
"Craig Small" <[email protected]> ("csmall") Thu, 9 Mar 2023 19:58:13 +1100
| Newsgroups | gmane.linux.procps.devel |
|---|---|
| Message-ID | <CALy8Cw42N23FuZLKTsdUs=PjL9fdzVAkSfzJRahSOGcd24Tx5w@mail.gmail.com> |
--000000000000eae5ed05f673d837 Content-Type: text/plain; charset="UTF-8" On Thu, 9 Mar 2023 at 00:48, Thorsten Kukuk <[email protected]> wrote: > 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, > I'd agree with them, the API is awful. What's their view on how to get a list of users? I looked at the coreutils package and they either use the functions or directly read the file. So if there is an alternative, which provides the needed features in a > more realible way not depending on utmp, I would prefer that. > So would I, but this solves only part of the problem. 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. > There are two options here: 1) Have count_users() check the return value and return 0 if sd_get_users() is <0 2) Just return a negative number and have procps_uptime_sprint() print something, such as "? users" for a negative return of count_users() #1 is the minimum and fixes the issue you have here, however, it's a bit sad. My preference is #2, it's broader than just fixing the utmp issue but gives a better result for the user. I was going to suggest updating count_users to return negative values for the utmp functions but most don't report errors! The man page doesn't even specify how to tell the difference between "no more users" and "I'm broken" for getutent(). People using the old utmp way get 0 users but we can't fix the utmp functions. > 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. > You'd be surprised what users do. I believe it is possible to have a non-systemd init/logind but have the libraries installed. Is that a good idea? No. Should libproc2 support that bad idea, probably? I'm hoping sd_get_sessions() returns a specific errno for that condition and we can use that for the fall-through. That will need a bit of work to see what it looks like. Hmm, looking at the systemd code: https://github.com/systemd/systemd/blob/main/src/libsystemd/sd-login/sd-login.c#L1022 The function looks for files in /run/systemd/sessions and if it can't find the directory returns -ENOENT Looks like this is what having the library but not the daemon looks like. Since libprocps uses already libsystemd: how do the other functions > behave in this case? > The functions are only called for specific systemd-only fields. If you have the systemd no daemon with library setup and type "ps -o seat" and get something strange for the value of a systemd seat, something your host has no concept of, you'd go well I expect that. The strange user count in w is probably not what they are expecting. So probably the idea is: If systemd or elogind is enabled: * call sd_get_sessions, >= 0 OR is not -ENOENT return that value * otherwise (returned -ENOENT) fallback to the old utmp functions If systemd or elogind not enabled: * use the old utmp functions Also, update procps_uptime_sprint() so if count_users return negative, print "? users" not "<random negative> users". That way I'm not going to have to deal with getting emails for the next decade from users asking "why does w display -2 users". For people who use systemd, they get a nice reliable 2038-ok count of users. For people who don't, well we've tried our best. People who use musl, they're already living the dream as they always have 0 users. - Craig --000000000000eae5ed05f673d837 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=3D"gmail_quote">= <div dir=3D"ltr" class=3D"gmail_attr">On Thu, 9 Mar 2023 at 00:48, Thorsten= Kukuk <<a href=3D"mailto:[email protected]" target=3D"_blank"= >[email protected]</a>> wrote:<br></div><blockquote class=3D"g= mail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204= ,204,204);padding-left:1ex">1. long or short term glibc developers want to = deprecate and remove the<br> utmp/wtmp/lastlog interfaces from glibc because they say it's legacy,<b= r></blockquote><div>I'd agree with them, the API is awful.</div><div>Wh= at's their view on how to get a list of users? I looked at the coreutil= s package and they either use the functions or directly read the file.</div= ><div><br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0= px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> So if there is an alternative, which provides the needed features in a<br> more realible way not depending on utmp, I would prefer that.<br></blockquo= te><div>So would I, but this solves only part of the problem.</div><br><blo= ckquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left= :1px solid rgb(204,204,204);padding-left:1ex"> But what would be a good way to report an error?<br> utmp would just don't return any utmp entries, which leads to a wrong <= br> "0 users" message. So the problem exists already today, but in a = way<br> that a user wouldn't even notice it.<br></blockquote><div>There are two= options here:</div><div>1)=C2=A0 Have count_users() check the return value= and return 0 if sd_get_users() is <0</div><div>2) Just return a negativ= e number and have procps_uptime_sprint() print something, such as "? u= sers" for a negative return of count_users()</div><div><br></div><div>= #1 is the minimum and fixes the issue you have here, however, it's a bi= t sad.</div><div>My preference is #2, it's broader than just fixing the= utmp issue but gives a better result for the user.</div><div>I was going t= o suggest updating count_users to return negative values for the utmp funct= ions but most don't report errors!</div><div>The man page doesn't e= ven specify how to tell the difference between "no more users" an= d "I'm broken" for getutent().</div><div>People using the old= utmp way get 0 users but we can't fix the utmp functions.</div><div><b= r></div><div></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0p= x 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> >=C2=A0 4) What happens if you have the systemd libraries installed but = not running<br> > systemd?<br> <br> I don't know and I don't think that anybody would compile/link an<b= r> application with systemd support without using systemd.<br> Linux distributors would not do that. People building their own<br> distribution wouldn't do that, too.<br> Other applications making more heavy use of libsystemd do just fail.<br></b= lockquote><div>You'd be surprised what users do. I believe it is possib= le to have a non-systemd init/logind but have the libraries installed.</div= ><div>Is that a good idea? No.</div><div>Should libproc2 support that bad i= dea, probably?<br></div><div><br></div><div>I'm hoping sd_get_sessions(= ) returns a specific errno for that condition and we can use that for</div>= <div>the fall-through. That will need a bit of work to see what it looks li= ke.<br></div><div><br></div><div>Hmm, looking at the systemd code:</div><di= v><a href=3D"https://github.com/systemd/systemd/blob/main/src/libsystemd/sd= -login/sd-login.c#L1022" target=3D"_blank">https://github.com/systemd/syste= md/blob/main/src/libsystemd/sd-login/sd-login.c#L1022</a></div><div>The fun= ction looks for files in /run/systemd/sessions and if it can't find the= directory returns -ENOENT</div><div>=C2=A0Looks like this is what having t= he library but not the daemon looks like.<br></div><div><br></div><blockquo= te class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px = solid rgb(204,204,204);padding-left:1ex">Since libprocps uses already libsy= stemd: how do the other functions<br> behave in this case?<br></blockquote><div>The functions are only called for= specific systemd-only fields.</div><div>If you have the systemd no daemon = with library setup and type "ps -o seat" and get something strang= e</div><div>for the value of a systemd seat, something your host has no con= cept of, you'd go well I expect that.</div><div><br></div><div>The stra= nge user count in w is probably not what they are expecting.</div></div><di= v class=3D"gmail_quote"><br></div><div class=3D"gmail_quote">So probably th= e idea is:</div><div class=3D"gmail_quote">=C2=A0 If systemd or elogind is = enabled:</div><div class=3D"gmail_quote">=C2=A0 * call sd_get_sessions, >= ;=3D 0 OR is not -ENOENT return that value</div><div class=3D"gmail_quote">= =C2=A0* otherwise (returned -ENOENT) fallback to the old utmp functions</di= v><div class=3D"gmail_quote">=C2=A0If systemd or elogind not enabled:</div>= <div class=3D"gmail_quote">=C2=A0* use the old utmp functions</div><div cla= ss=3D"gmail_quote"></div><div class=3D"gmail_quote">Also, update procps_upt= ime_sprint() so if count_users return negative, print "? users" n= ot "<random negative> users".</div><div class=3D"gmail_quot= e">That way I'm not going to have to deal with getting emails for the n= ext decade from users asking "why does w display -2 users".<br></= div><div class=3D"gmail_quote"><br></div><div class=3D"gmail_quote">For peo= ple who use systemd, they get a nice reliable 2038-ok count of users. For p= eople who don't, well we've tried our best.</div><div class=3D"gmai= l_quote">People who use musl, they're already living the dream as they = always have 0 users.<br></div><div class=3D"gmail_quote"><br></div><div cla= ss=3D"gmail_quote">=C2=A0- Craig</div><div class=3D"gmail_quote"><br></div>= </div> --000000000000eae5ed05f673d837--