who -q no longer counts gui users

Bug #875817 reported by DAP on 2011-10-16
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
mythtv (Ubuntu)
Undecided
Unassigned

Bug Description

The "checklogin.sh" script on this page: http://www.mythtv.org/wiki/ACPI_Wakeup uses "who -q" to determine if a user is logged in to prevent MythTV from shutting down the computer when a user is using the computer.
On 11.04 this worked fine.
On 11.10, my system shuts down 10 minutes after booting unless I open a terminal window.
On opening a terminal window and running "who -q" I get:
$ who -q
dpeale
# users=1
I used to get "users=2". The gui user is not counted anymore.
This is true of both Unity and Gnome GUIs

The 'w' command also has the same bug (I've never been able to figure out what package that comes from). It also has another bug. If you use one of the ctl-alt-Fx screens, login, and then logout, it continues to count that screen as logged in.

ProblemType: Bug
DistroRelease: Ubuntu 11.10
Package: coreutils 8.5-1ubuntu6
ProcVersionSignature: Ubuntu 3.0.0-12.20-generic 3.0.4
Uname: Linux 3.0.0-12-generic x86_64
ApportVersion: 1.23-0ubuntu3
Architecture: amd64
Date: Sun Oct 16 09:24:27 2011
InstallationMedia: Ubuntu 11.04 "Natty Narwhal" - Release amd64 (20110427.1)
ProcEnviron:
 PATH=(custom, no user)
 LANG=en_US.UTF-8
 SHELL=/bin/bash
SourcePackage: coreutils
UpgradeStatus: Upgraded to oneiric on 2011-10-15 (0 days ago)

DAP (akadap) wrote :
C de-Avillez (hggdh2) wrote :

Thank you for opening this bug and helping make (Myth)Ubuntu better. This is not a bug on 'who'; the only thing 'who' does is read /var/run/utmp, and report based on it. What happens is running programs must use the utmp protocol to update utmp -- so there is at least one such program on 11.10 that is *not* doing that (and this program was the one that populated utmp so that 'checklogin.sh' was working correctly.

As such, I have reset the package to 'mythtv'.

affects: coreutils (Ubuntu) → mythtv (Ubuntu)
Mario Limonciello (superm1) wrote :

I think it would be much better for the query to use consolekit to figure out who's logged in instead.

Any interactive sessions will be listed there.
'ck-list-sessions'

C de-Avillez (hggdh2) wrote :

By the way, you stated you could not find which package carries 'w'. Here is what I did:

(1) whereis w -- returns 'w: /usr/bin/w.procps /usr/bin/w /usr/share/man/man1/w.1.gz'
(2) apt-file search /bin/w (I am lazy) -- returns many entries, none of them seem to apply;
(3) ls -l /usr/bin/w -- returns '/usr/bin/w -> /etc/alternatives/w'

Ah, so it is managed by Alternatives. So now we can either 'ls -l /etc/alternatives/w', or 'update-alternatives --list w'. Both of them point to /usr/bin/w.procps

Now we run, again, 'apt-file search /usr/bin/w.procps' -- returns 'procps: /usr/bin/w.procps'.

So 'w' belongs to the procps package.

DAP (akadap) wrote :

This re-clasification is a problem since the "checklogin.sh" script is not actually a part of mythtv. It is a user written script that exists and is maintained only on the mythtv wiki.

Let me give a bit of history of what was attempted to make this work:

The first attempt used 'last | grep "still logged in"' This failed once a month since it relied on a log file that was erased once a month. The first time the computer was turned on at the beginning of the month, the user would login, the log file would get erased, and there was no longer any record of the user being logged in, so mythtv would shut the computer down on them as they were using it.

The second attempt was the command 'w | grep " 0 users"' This failed when a user would use the ctl-alt-Fx command and log in on a different text screen. The problem here is that even though the user would log out, the users count would never decrement. This would leave the computer running forever even after the user logged out since the user count would never go to zero.

The third attempt was the command 'who -q | grep "users=0"'. This worked until the update to 10.10.

I just looked at the ck-list-sessions command. This does not give me a count of the number of users logged in. This command is undocumented, there is no man page or info page. A google search for 'ck-list-sessions' finds plenty of bug reports against it, but as far as I could tell, no documentation. Since it is not clear what this command is reporting, or what it will report when no one is logged in, I'm not clear on how I can use it.

Looking at the man page for utmp, it is clear that who -q will be unreliable for the purpose of determining how many are logged in since it appears both gnome and unity ignore the utmp file.

So I am left with no clear way of determining if anyone is currently logged into the computer. I'd like a solution that would survive OS upgrades so I don't have to keep patching this script.

Mario Limonciello (superm1) wrote :

Consolekit is exactly for this purpose; tracking users, logins, and seats. You can read a little bit more about it at http://www.freedesktop.org/wiki/Software/ConsoleKit

It reports all of this through modern mechanisms; dbus. Basically any interactive (local or remote) session will invoke a console kit session. This is why you'll see things like SSH listed in it as well as X.

ck-list-sessions is actually a wrapper tool around it's dbus interface. It will show you lots more information than you probably care about, but it can certainly tell you whether a user is logged in or not. That tool itself might not be well documented, but that's because it's output is pretty self explanatory. You can read it's code here to understand more if you're a bit confused still:
http://cgit.freedesktop.org/ConsoleKit/tree/tools/list-sessions.c

I think the best thing for you to do though is read the documentation. The DBUS api is documented there and you can take advantage of it. http://www.freedesktop.org/software/ConsoleKit/doc/ConsoleKit.html

Mario Limonciello (superm1) wrote :

And to clarify why 'w' behavior changed, I'm betting it's to do with the transition to lightdm from gdm.

DAP (akadap) wrote :

From the documentation of ConsoleKit:
"

Defining the Problem

To be written.

"

The documentation then dives directly into implementation details.

I attempted to read the rest of the documentation, but with the problem it is trying to solve undefined, it is not making any sense to me.

Also, from what I can gather it is an "opt in" system like utmp. What is there to guarantee that every gui or login method for the computer will use this? Isn't there a way to tell if a user is logged in without the gui or cli itself being required to write to some log file or database? The requirement to write to said log file or database is guaranteed to be forgotten by some gui or cli at some point (as it seems is proven by the fiasco of utmp), and forgetting to do this is not even considered a bug.

DAP (akadap) wrote :

"You can read it's code here to understand more if you're a bit confused still:
http://cgit.freedesktop.org/ConsoleKit/tree/tools/list-sessions.c"

Wow, 400 lines of code without a single comment.

The basic thing I'm missing is "Why?" Why does ConsoleKit exist? What function, in high level terms, does it perform? What is it good for?
Looking at source code only tells me "How". How it does what it does. But knowing it adds 3+4 and puts it in pointer 'Z' gives me no clue as to why. Someone who has intimate knowledge of how Linux works might be able to infer why it does that, but to the layman, even one who knows the 'C' programming language, it is opaque.

DAP (akadap) wrote :

When I'm logged in and have a terminal window open, I get:

$ ck-list-sessions
Session2:
        unix-user = '1000'
        realname = 'Douglas Peale'
        seat = 'Seat1'
        session-type = ''
        active = TRUE
        x11-display = ':0'
        x11-display-device = '/dev/tty7'
        display-device = ''
        remote-host-name = ''
        is-local = TRUE
        on-since = '2011-10-23T02:31:47.631922Z'
        login-session-id = '4294967295'

When I'm logged in and have no windows open I get the same thing.

When I'm logged out I get:

$ ck-list-sessions
Session4:
        unix-user = '117'
        realname = 'Light Display Manager'
        seat = 'Seat1'
        session-type = 'LoginWindow'
        active = TRUE
        x11-display = ':0'
        x11-display-device = '/dev/tty7'
        display-device = ''
        remote-host-name = ''
        is-local = TRUE
        on-since = '2011-10-23T03:18:26.759967Z'
        login-session-id = '4294967295'

I'm not sure how I can reliably use that to determine that no user is logged in.

Download full text (3.3 KiB)

Interesting that lightdm login screen shows as a session. Unless that is a
bug, could you check if realname = 'Light Display Manager'

On Sat, Oct 22, 2011 at 8:29 PM, DAP <email address hidden> wrote:

> When I'm logged in and have a terminal window open, I get:
>
> $ ck-list-sessions
> Session2:
> unix-user = '1000'
> realname = 'Douglas Peale'
> seat = 'Seat1'
> session-type = ''
> active = TRUE
> x11-display = ':0'
> x11-display-device = '/dev/tty7'
> display-device = ''
> remote-host-name = ''
> is-local = TRUE
> on-since = '2011-10-23T02:31:47.631922Z'
> login-session-id = '4294967295'
>
> When I'm logged in and have no windows open I get the same thing.
>
> When I'm logged out I get:
>
> $ ck-list-sessions
> Session4:
> unix-user = '117'
> realname = 'Light Display Manager'
> seat = 'Seat1'
> session-type = 'LoginWindow'
> active = TRUE
> x11-display = ':0'
> x11-display-device = '/dev/tty7'
> display-device = ''
> remote-host-name = ''
> is-local = TRUE
> on-since = '2011-10-23T03:18:26.759967Z'
> login-session-id = '4294967295'
>
> I'm not sure how I can reliably use that to determine that no user is
> logged in.
>
> --
> You received this bug notification because you are a member of Mythbuntu
> Bug Team, which is subscribed to mythtv in Ubuntu.
> https://bugs.launchpad.net/bugs/875817
>
> Title:
> who -q no longer counts gui users
>
> Status in “mythtv” package in Ubuntu:
> New
>
> Bug description:
> The "checklogin.sh" script on this page:
> http://www.mythtv.org/wiki/ACPI_Wakeup uses "who -q" to determine if a
> user is logged in to prevent MythTV from shutting down the computer when a
> user is using the computer.
> On 11.04 this worked fine.
> On 11.10, my system shuts down 10 minutes after booting unless I open a
> terminal window.
> On opening a terminal window and running "who -q" I get:
> $ who -q
> dpeale
> # users=1
> I used to get "users=2". The gui user is not counted anymore.
> This is true of both Unity and Gnome GUIs
>
> The 'w' command also has the same bug (I've never been able to figure
> out what package that comes from). It also has another bug. If you use
> one of the ctl-alt-Fx screens, login, and then logout, it continues to
> count that screen as logged in.
>
> ProblemType: Bug
> DistroRelease: Ubuntu 11.10
> Package: coreutils 8.5-1ubuntu6
> ProcVersionSignature: Ubuntu 3.0.0-12.20-generic 3.0.4
> Uname: Linux 3.0.0-12-generic x86_64
> ApportVersion: 1.23-0ubuntu3
> Architecture: amd64
> Date: Sun Oct 16 09:24:27 2011
> InstallationMedia: Ubuntu 11.04 "Natty Narwhal" - Release amd64
> (20110427.1)
> ProcEnviron:
> PATH=(custom, no user)
> LANG=en_US.UTF-8
> SHELL=/bin/bash
> SourcePackage: coreutils
> UpgradeStatus: Upgraded to oneiric on 2011-10-15 (0 days ago)
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/ubuntu/+source/mythtv/+bug/875817/+subscriptions
>
> _______________________________________________
> Mailing list: https://launchpad.net/~mythbuntu-bugs
> Post to ...

Read more...

DAP (akadap) wrote :

I could, and it work for me, but it is not a general solution as that is not the only available login screen tool, and it is likely to break on the next update of Ubuntu.

I had thought "session-type" might be a better option, but the documentation basically says "UNDEFINED DO NOT USE!".

DAP (akadap) wrote :

Also the presence of 'Light Display Manager' does not imply that no one is logged in. I get this when logged into a virtual console:

ck-list-sessions
Session3:
        unix-user = '1000'
        realname = 'Douglas Peale'
        seat = 'Seat1'
        session-type = ''
        active = TRUE
        x11-display = ''
        x11-display-device = ''
        display-device = '/dev/tty2'
        remote-host-name = ''
        is-local = TRUE
        on-since = '2011-10-23T03:30:14.863295Z'
        login-session-id = '4294967295'
        idle-since-hint = '2011-10-23T03:31:54.666635Z'
Session4:
        unix-user = '117'
        realname = 'Light Display Manager'
        seat = 'Seat1'
        session-type = 'LoginWindow'
        active = FALSE
        x11-display = ':0'
        x11-display-device = '/dev/tty7'
        display-device = ''
        remote-host-name = ''
        is-local = TRUE
        on-since = '2011-10-23T03:30:47.369030Z'
        login-session-id = '4294967295'

I'm on my phone, so please excuse the shortness of this. But couldn't you
see what sessions were logged in and if not all were the light dm then
someone is logged in?
 On Oct 23, 2011 9:47 AM, "DAP" <email address hidden> wrote:

> I could, and it work for me, but it is not a general solution as that is
> not the only available login screen tool, and it is likely to break on
> the next update of Ubuntu.
>
> I had thought "session-type" might be a better option, but the
> documentation basically says "UNDEFINED DO NOT USE!".
>
> --
> You received this bug notification because you are a member of Mythbuntu
> Bug Team, which is subscribed to mythtv in Ubuntu.
> https://bugs.launchpad.net/bugs/875817
>
> Title:
> who -q no longer counts gui users
>
> Status in “mythtv” package in Ubuntu:
> New
>
> Bug description:
> The "checklogin.sh" script on this page:
> http://www.mythtv.org/wiki/ACPI_Wakeup uses "who -q" to determine if a
> user is logged in to prevent MythTV from shutting down the computer when a
> user is using the computer.
> On 11.04 this worked fine.
> On 11.10, my system shuts down 10 minutes after booting unless I open a
> terminal window.
> On opening a terminal window and running "who -q" I get:
> $ who -q
> dpeale
> # users=1
> I used to get "users=2". The gui user is not counted anymore.
> This is true of both Unity and Gnome GUIs
>
> The 'w' command also has the same bug (I've never been able to figure
> out what package that comes from). It also has another bug. If you use
> one of the ctl-alt-Fx screens, login, and then logout, it continues to
> count that screen as logged in.
>
> ProblemType: Bug
> DistroRelease: Ubuntu 11.10
> Package: coreutils 8.5-1ubuntu6
> ProcVersionSignature: Ubuntu 3.0.0-12.20-generic 3.0.4
> Uname: Linux 3.0.0-12-generic x86_64
> ApportVersion: 1.23-0ubuntu3
> Architecture: amd64
> Date: Sun Oct 16 09:24:27 2011
> InstallationMedia: Ubuntu 11.04 "Natty Narwhal" - Release amd64
> (20110427.1)
> ProcEnviron:
> PATH=(custom, no user)
> LANG=en_US.UTF-8
> SHELL=/bin/bash
> SourcePackage: coreutils
> UpgradeStatus: Upgraded to oneiric on 2011-10-15 (0 days ago)
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/ubuntu/+source/mythtv/+bug/875817/+subscriptions
>
> _______________________________________________
> Mailing list: https://launchpad.net/~mythbuntu-bugs
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~mythbuntu-bugs
> More help : https://help.launchpad.net/ListHelp
>

DAP (akadap) wrote :

That would only work if "Light Display Manager" was the only login manager in existence, and everyone used it.

I need some way to distinguish between human interactive users that the computer should not shut down on and automated sessions that the computer can be shut down on.

The reality is though that I really should not have to do this at all. Cron should be extended to handle the wake up timer, and handle the decision on when to shut down the computer, when it should turn itself on, and when it should remain on. It is an oddity that MythTV is allowed to control such a global resource, and us users have to try and add patches to extend its functionality.

C de-Avillez (hggdh2) wrote :

@DAP: "This re-clasification is a problem since the "checklogin.sh" script is not actually a part of mythtv. It is a user written script that exists and is maintained only on the mythtv wiki."

Yes, it is a problem. But -- although I agree with you that we should have something more robust to find who -- if anyone -- is logged in, this is *not* a problem with coreutils; at the point in time I reset the bug to mythtv I have no idea this was not part of the official mythtv distro (I do not use it). So, right now, and until something more tangible lands here. mythtv is still not a bad place. Alternatively, we could, I guess, open a task on Ubuntu itself and set it to WISHLIST.

I do think we miss something to check for a *local* user logged in. 'who' (or 'w', it seems) do not do the trick, since it relies on UTMP. I think this would benefit *all* Linux distros.

It sounds like Mario's suggestion is still a good one: write a wrapper over 'ck-list-sessions', or extend it, to provide the functionality you (we all, in fact) need. Unfortunately I do not have time to do that right now... sorry.

May I suggest you to contact the MythTV community on that?

Looking at your comment #13 -- LightDM will only be shown if there is no logged-in user (under LightDM itself). Note that you logged in on a pseudo-terminal (tty2).

DAP (akadap) wrote :

I logged into the pseudo-terminal (tty2) locally by ctl-alt-F2 switching away from the login screen, so I was locally logged in, and "LightDM" still showed up.
ck-list-sessions is just not sufficient to distinguish the possible cases of someone logged in vs no one logged in.

If we are going to convert this to a wish list, I'd rather have cron updated so that it takes control of the wake timer and handles the waking and auto-shutdown itself.
I would think that there are many applications besides just MythTV where it would be useful to have a computer that wakes to run a scheduled task, and shuts itself down when there is no one using the computer, and no scheduled tasks in the near future.

This does not mean I think that a reliable way to determine if a user is logged in is not necessary, in fact it would be required to properly implement an updated chron tool.

Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in mythtv (Ubuntu):
status: New → Confirmed
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers