boinc icon indicating copy to clipboard operation
boinc copied to clipboard

redesign Linux idle detection

Open davidpanderson opened this issue 1 year ago • 1 comments

Related issues: #3405, #1187

The notion of "in use" (for computing preferences) means any interactive use of the host. This includes:

  1. a physical terminal connected via RS-232
  2. remote login with ssh
  3. an xterm window on the local X11 server
  4. other interactive X11 applications ... am I missing anything?

Currently the client checks for input in two ways: a) looking at the access time of tty and pty entries in /dev. In theory this should handle cases 1-3); remote logins and xterms create a pseudo-tty. b) attempting to connect to the local X11 server, and doing a XScreenSaverQueryInfo() call. This is intended to handle case 4.

b) apparently doesn't work when the client runs as use "boinc". And it has been argued that the client shouldn't be connecting to ports like 6000; who knows what's there, and the client can hang.

Proposal:

  • verify that method a) actually works like we think it does, on all major distros, no matter what user/group the client runs as.

  • Don't do X11 stuff in the client. Instead, do what we do on Windows: A small "monitor" program (to be run as the desktop user) creates a shared-mem segment, periodically queries the X server and writes the time of last user input to shared mem. The client checks for the existence of this segment and reads it.

    Note: the Manager (which runs as the desktop user) could and should perform the same function as the monitor program. We should provide the monitor program for people who don't want to use the Manager.

Contact point: @AenBleidd

davidpanderson avatar May 05 '23 21:05 davidpanderson

This was insightful to find where areas I should focus on and which could be a possible way to detect idle in the system, At first, I was trying to read devices activity to check for idle in headless systems which was a stupid idea because the command w is a better method to do this. So for case 1 the command w should work, but it doesn't know about the activity when X11 is present here is an example: image

In the case of X11 is present, using xprintidle is the way. It doesn't work if X11 is active on another user because it needs authorization from that user, a workaround is to use pkexec from root as the user who has active X11 to authorize whoever uses is executing xprintidle which should be revoked before the program exits (e.g receiving Ctrl-c signal).

in the case of Wayland ( luckily most people use Xwayland), there is something in the docs that I haven't checked yet but I will try to figure it out.

Lastly, none of the above works with ssh because it doesn't report anything. It has its own idle checker that I couldn't access or figure it out. If I wasn't able to detect the activity or check idle for ssh in normal ways I will think out of the box and try to detect any traffic on the ssh port when it's open after reading the ssh port from sshd_config to see any activity. This method works I tried a simple python to make sure.

The final idle time should be easily accessible to any tool or system and using shared memory is not a good idea for me, not because it's bad but because I believe it's not the philosophy of linux so instead it will write the time to a file in /tmp

and of course, this should be a standalone tool instead of being part of boinc.

Any thoughts on this?

0x0OZ avatar Oct 05 '23 15:10 0x0OZ