systemd/python-systemd

uids and sessions returned by login.uids() and login.sessions() are not in order

Coderx7 opened this issue · 2 comments

I noticed the login.uids() and login.sessions() report their results without any meaningful order.
That is, one can not determine which session belongs to which uid.
This is an example demonstrating the difference between what is given by the mentioned methods and what is given by the loginctl list-sessions:

uids = login.uids()
sessionsd = login.sessions()
INFO:root:uids: [121, 1000]
INFO:root:sessions: ['2', 'c1']

the output of loginctl list-sessions:

INFO:root:sessions: 
SESSION        UID     USER        SEAT           TTY             
   2          1000    hossein      seat0          tty2            
  c1          121      gdm         seat0          tty1            

2 sessions listed.

As you can see it seems the lists are sorted which shouldn't be the case as it makes it impossible to couple uid with a respective session id.

it would however, make more sense imho, to have a new method that returns the uid:sessionid pair (it can contain more than session id, but thats just an example for our specific case), but until then, they need to at least have the same order for them to be usable

Those two functions simply give back the data that sd_get_uids() and sd_get_sessions() return. But loginctl list-sessions doesn't use either, and goes over dbus instead. In fact there is no relation between the lists returned by sd_get_uids() and sd_get_sessions(). For example, if you have two sessions for one user, you'll get an array with one item from sd_get_uids().

I guess the correct solution to get the type of data you want would be to copy what loginctl does and go over dbus too. But that is out of scope for this module, which only wraps the C APIs.

I'll close this, per the comment above. We won't be adding dbus code this this package, so this is unlikely to get fixed here.