uutils / coreutils

Cross-platform Rust rewrite of the GNU coreutils
https://uutils.github.io/
MIT License
17.6k stars 1.27k forks source link

`uu-uptime` finds 12 users while `gnu-uptime` finds only 1 #6493

Closed vincentdephily closed 3 months ago

vincentdephily commented 3 months ago

Uutils finds more users than GNU, on a Linux (Gentoo) Systemd KDE single-user desktop:

$ uptime
 12:30:16 up 9 days, 17:36,  1 user,  load average: 19.95, 19.71, 13.36
$ ./target/debug/coreutils uptime 
 12:30:21  up 9 days 17:36,  12 users,  load average: 19.23, 19.56, 13.35

Looking at strace, GNU seems to get the info from /run/systemd/sessions (despite /run/systemd/sessions/10 starting with This is private data. Do not parse.), while uutils opens /var/run/utmp.

FWIW, I added some debug in src/uu/uptime/src/platform/unix.rs to get the pid/user/is_user_process and I get (with "work" being my username on this system):

0 "reboot" false
9994 "" false
535036 "work" true
535074 "work" true
536408 "work" true
538194 "work" true
710842 "work" true
544777 "work" true
710988 "work" true
714806 "work" true
536385 "work" false
876606 "work" true
526168 "work" true
874586 "work" true
938703 "LOGIN" false
1014898 "work" true
1032382 "work" false

Using git main branch, 92c3de538755d69b7fa3d79030ca5dff44445809

sylvestre commented 3 months ago

Nice bug :)

cakebaker commented 3 months ago

What's the output of uptime --version? My guess is you are using uptime from procps-ng, not from GNU. At least on my machine with Arch Linux it doesn't use the GNU version and I see a similar difference in the number of users. However, when I use the GNU version I get the same output as with uutils.

vincentdephily commented 3 months ago

Ah, good catch, I'm using uptime from procps-ng 4.0.4, not GNU uptime. My distro doesn't seem to package GNU uptime, but building that from git I get the same behavior between uutils and GNU.

Closing as invalid, sorry for the noise.