who (or w) does not report correctly idle time

Bug #268780 reported by Zakhar
4
Affects Status Importance Assigned to Milestone
linux (Ubuntu)
Triaged
Low
Unassigned

Bug Description

Binary package hint: coreutils

Release: [Ubuntu 8.04.1]
---------

Package: coreutils (included in the core of Ubuntu)
----------
cat /proc/version
Linux version 2.6.24-19-generic (buildd@king) (gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu7)) #1 SMP Wed Aug 20 17:53:40 UTC 2008

When you do :

info coreutils 'who invocation'

The documentation says :

`-u'
     After the login time, print the number of hours and minutes that
     the user has been idle. `.' means the user was active in the last
     minute. `old' means the user has been idle for more than 24 hours.

What I expect to happen
-------------------------------
When you type the command
who -u
who -a
w

I expect to happen what is written in the documentation: get the idle time.

To my understanding, 'idle' means that the user does not use any input device : keyboard, mouse, touchpad, tablet...

What I get instead:
-----------------------
The "bug" is that mouse events are not at all taken into account (I don't know for tablets, joystisk...)

How to reproduce the "bug":
------------------------------------

To check that, put the following script on you desktop :

who.sh
#######
#!/bin/bash
who -a
read key

Then DO NOT touch the keyboard, and launch the script with the mouse.
Kill it also with the mouse.

You'll see the idle timer going up for your user + tty7 (if you are using default Ubuntu settings for your graphical desktop), although you are not idle because you moved the mouse and clicked.

Same if you replace who by w

Conclusion:
--------------
So either the behavior is wrong, or the documentation is inacurate about what is considered being idle.

Related suggestion:
-------------------------
It could also be added in the documentation, that idle time is ALSO reported as 'old' when the user has always been idle (in the meaning 'who' gives to it) since the beginning of the session. So in fact, the user might have been active just a few minutes before on another session, and it's not only when you have "more than 24 hours" of 'idle'.

May be related bugs:
---------------------------
Second bug with the idle timer, when you open a remote X session (for instance, CTRL+ALT+F1 and X -query 192.168.0.XXX :1), the idle timer is ALWAYS reported as 'old' in this session, even if you do keyboard inputs.
It is seen as 'old' by the remote user, or by an user connected locally to this remote station.

Revision history for this message
jjos (jbenjos) wrote :

Zakhar,

I was able to confirm this bug using the suggestion you described.

Changed in coreutils:
status: New → Confirmed
Revision history for this message
Zakhar (alainb06) wrote :
Download full text (3.6 KiB)

After a few time of reflexion, here are my comments / suggestions about this bug.

Who seems to be mainly a frontend to display nicely the informations in /var/run/utmp (or /var/log/wtmp for the history).
The documentation says that these files, unfortunately (because it's not vey good architecture) are used by several other parts of Linux and shouldn't be changed.

As it is not wise to change these files, or the way the informations are stored in the files (I'm not skilled enough to measure the impact of a change in these files)

First point of view can be :
-----------------------------------
- who is a "console" tool, and thus is unaware of any program using devices such as a mouse, a joypad, etc...

Such a point of view would be relevant and coherent to the "console" nature of the who command.

But then two things are to be taken into consideration if this point of view is accepted:
- the "bug" is in the documentation. Because mouses are so common, when an average person reaads "user has been idle", he is bound to think that mouse movements are taken into account. So the documentation MUST be more precise. It MUST be explicitly written that idle means only "did not touch the keyboard".
- in a script you have no way of knowing the "real" idle status of the user. I mean of course, an idle status taking into account mouse inputs or other input devices operated by the user.

For this second issue, it can be moved to the various GUI: Gnome, KDE, etc, (or X server ?) all know if their user is active or not, mouse included, screensaver proves it.
Of course it would be much better if there was an unique way to include mouse inactivity for scripts (or "real" idle status).
A unique method would allow scripting for any graphical environment.

A second point of view,
---------------------------------
although the first option is relevant, is to remember that who is only a frontend.
The workaround would then be to add an option that would call the GUI in use (or X?) and ask for details about idle timers.

For example: who -g
could call Gnome, KDE, etc... and report idle timer seen by the GUI.

This workaround has the advantage that it does not disrupt the other options or the format and feeding of /var/run/utmp, but would report more relevant informations for scripts who want to run when there is no user for some time (my initial need).

Important suggestion:
------------------------------
when you write a script that is supposed to run when there are no active users for some time (initial need) you are also interested by a "flag" all GUI (or X ?) most probably support. I'm thinking of the "do not go to screensaver" flag. Most important example is when a user is watching a movie: he doesn't want screensaver! And even if he is not touching keyboard or mouse, you can assume there is a user. So if the script is highly I/O or CPU consuming and could disrupt movie playback, you do not want to start your script.

So, if a who -g (or who -X if the information is commonly handled by the X server) is added, I would strongly recommend, as a specification to display as well such a "do not go to screensaver" flag.

And second bug:
-----------------------
has t...

Read more...

Revision history for this message
C de-Avillez (hggdh2) wrote :

Thank you for reporting this bug and helping make Ubuntu better. I am downgrading this bug temporarily to Incomplete: 'who' (and 'pinky', a reduced version of 'finger') base their output on the utmp(5) file. Neither goes anywhere else.

In other words, 'who' is very much restricted to browsing the 'utmp' file contents. This is a major problem to what you want, since (1) most X programs do not write events to utmp; (2) the, huh, "event" you are looking for is something similar to "user is idling", and this event is not recorded (and, I think, not even defined) on utmp.

An additional point is that, no matter what, 'who' is a core utility: it does not depend on anything else but the basic *IX system it is running under; it does not know, or care, if a running programme is graphical or not, or what it is doing. All it knows about is entries in the utmp file. So, if a program (like most X) does *not* update utmp, then 'who' will not know about it.

Although in a different scenario, this has been explained in the coreutils mailing list at http://lists.gnu.org/archive/html/bug-coreutils/2007-07/msg00018.html.

I am searching for similar scenarios meanwhile, since somebody must have had this type of issue before. So far I have found a BOINC ticket, still open, on that: http://boinc.berkeley.edu/trac/ticket/463.

Meanwhile, please feel free to propose your changes upstream, at the coreutils mailing list: simply email <email address hidden>.

Changed in coreutils:
status: Confirmed → Incomplete
importance: Undecided → Low
Revision history for this message
Zakhar (alainb06) wrote :
Download full text (4.6 KiB)

I do agree with your answer, it's what I suggest as possible anwser n°1.
Basically, if the answer is so, what I say is there is still a bug... in the documentation. Because who is a 30 years old *ix legacy, at this time a mouse was not a frequent input device, hence the documentation does not mention it. Nowadays, when someone reads on a documentation: "user is idle", he is bound to think: no mouse input.
So I'm fine with the answer, but "man-people" (or is it core-utils people ?) should modify the man pages about who so that it is clear to everyone reading that idle means only "no keystrokes" were made, and that mouse or other input devices are not taken into account.

Let's go back to my scenario.
I have a PC (with Hardy) that is used either
- as a regular PC: someone is in front of the PC doing some stuff!
or
- as an unattended streaming server, to stream movies (uses VLC with local ISP as source).
When PC is used as an unattended server, it is powered on from a distant location using Wake On Wan.
From this distant location we can then look video streams (French TV), and of course, the remote interface has a button to stop the server. But sometimes, we just exit the remote interface and forget to hit the shutdown-the-server button.
In that case, I don't want the remote server to remain powered on for hours or even days! Of course, it is why Wake On Wan is used also, because remote server is powered down by default when not in use.

So, I saw a small cron'ed-script someone made public on the Ubuntu forum, to auto-power-down a PC on "inactivity".
I adapted the script a little bit, because when someone is watching TV from the remote location it has to be detected as "activity". That is done with the remote-player (I adapted VLC HTTP interface remote HTML pages that are quite buggy by the way!), it sends an Ajax (XHR) request to the server every minute to mark its remote activity.

So the script has this logic:
- if it ever sees "local activity", it will never power down the PC (means someone is here, we do not want to shutdown PC then)
- if it sees "remote" activity : do not stop the PC
- if after 10 minutes, there is no "remote" activity, and never seen any "local activity" => shutdown.

As the example on the forum used who, I did the same.

I ran in this "who issue", when one day my father used the PC locally to watch a movie. As he did that without ever touching the keyboard, only mouse moves & clicks, who detected no local activity and PC was shutdown after 10 minutes!

So who was a "solution" (not a good one obviously).
The "need" is to detect properly user activity (including mouse, touchpad, joystick, tablet....)

I would be very glad if there were some way to do that, such as look into some /proc/idle (which does not exist, I'm making that up!)

Writing this cron'ed script, I was mislead by the documentation saying who reports "idle user".

So to sumarize:
- who does not report mouse activity.
- it's OK as who is very old stuff, and relies on "bad" architecture, we do not want to change it.
- anyway, as mouse is so obvious nowadays, I strongly suggest documentation (man pages) is changed to mark who limitation to keyboard only.
- th...

Read more...

Revision history for this message
Phillip Susi (psusi) wrote :

Wow this is an old one, and seems to have gotten worse. Now even keyboard input does not reset the idle timer.

Changed in coreutils (Ubuntu):
status: Incomplete → Triaged
Revision history for this message
C de-Avillez (hggdh2) wrote :

@Phillip: I am confused -- why do you think this is a 'who' issue? 'who' is a *browser* -- it only _reads_ the UTMP file, it does not change it at all. And, since more and more programmes do not update UTMP, 'who' is getting more and more unreliable.

Revision history for this message
Phillip Susi (psusi) wrote :

I agree. I was thinking of reassigning it to Xorg, but wasn't sure that was the correct component that is supposed to be updating utmp. Is the utmp file really updated every time you touch a key, and if so, by what program? I was thinking that can't be the case, so there must be some way the utility queries the kernel about the idle time on that tty.

Revision history for this message
Phillip Susi (psusi) wrote :

Well, it seems that who computes the idle time by using the timestamps of the tty device file, which are updated every time a process reads input. The problem is that X ( and also emacs ) don't read from the tty, so the timestamps are not updated.

I think that fixing this is going to require overhauling the virtual console code to move the VC ttys under the /dev/pts filesystem so that /dev/tty can actually open the proper inode, and so that there can be a master inode to update when events come in rather than when they are read. Oh boy.

affects: coreutils (Ubuntu) → linux (Ubuntu)
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.