#1135886 procps: inconsistent login time in "w -t" output for X terminals

Package:
procps
Source:
procps
Description:
/proc file system utilities
Submitter:
Vincent Lefevre
Date:
2026-05-07 12:32:02 UTC
Severity:
normal
#1135886#5
Date:
2026-05-07 01:54:22 UTC
From:
To:
In the output of "w -t", for most X terminals (such as xterm, rxvt,
mlterm, sakura), the time in the "LOGIN@" column seems to be the
start time of the login session ("loginctl session-status self",
or id given by /proc/self/sessionid) instead of the time when the
terminal was started. The login session is

3 - vinc17 (1000)
  Since: Sat 2026-05-02 04:25:02 CEST; 4 days ago
  State: active
 Leader: 2197 (lightdm)
   Seat: seat0; vc7
Display: :0
 Remote: no
Service: lightdm
   Type: x11
  Class: user
Desktop: lightdm-xsession
   Idle: no
   Unit: session-3.scope
[various processes, including these terminals]

There is no such issue with GNOME Terminal, but it does not belong
to any login session: "loginctl session-status self" outputs

  Failed to get path for session 'self': Caller does not belong to
  any known session.

and "loginctl session-status $(cat /proc/self/sessionid)" just gives

4 - vinc17 (1000)
  Since: Sat 2026-05-02 04:25:02 CEST; 4 days ago
  State: active
 Leader: 2372 (systemd)
 Remote: no
Service: systemd-user
   Type: unspecified
  Class: manager
   Idle: no

without any unit and processes (and no seat, no display).

So it seems that you should not rely on systemd-logind information.

#1135886#10
Date:
2026-05-07 02:15:01 UTC
From:
To:
of them for the addition of the -t (--terminal) option, though they
come from the upstream repository (but there might be a divergence).

#1135886#15
Date:
2026-05-07 11:20:01 UTC
From:
To:
I'd be curious about that myself. 4.0.4-9 does have the upstream 4.0.6 w -t
patches,
so it should be the same.

I use Gnome terminal myself, so it works fine for me.

The way terminal mode works is that it scans all processes and sorts by tty
and PID.
So something like "ps -e -o tty,start,comm --sort=tty,pid"

look for the tty column to change, that process start time is the login
time.

eg snipped ps output
[...]
pts/0      May 06 bash   <-- this
[...]
pts/1    20:46:26 bash <-- this
pts/2    20:57:50 bash <-- this
pts/2    21:03:03 vi
tty2       May 06 gdm-wayland-ses  <-- this
tty2       May 06 gnome-session-b

$ w -t
 21:12:04 up 1 day, 13:21,  1 user,  load average: 0.25, 0.26, 0.22
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU  WHAT
csmall   tty2     -                Wed07   37:21m  0.00s   ?
 /usr/libexec/gdm-wayland-session /usr/bin/gnome-session
csmall   pts/0    -                Wed13    4.00s  0.06s  0.06s w -t
csmall   pts/1    -                20:46   25:39   0.01s  0.01s bash
csmall   pts/2    -                20:57    4:15   0.56s  0.01s vi src/w.c

This method is used if there is no systemd session, as you've noticed there
isn't one for the terminal. That is actually the reason for -t mode
otherwise "normal" w would work.

So... why is the tty switch trick not working for your terminals?

 - Craig

#1135886#20
Date:
2026-05-07 12:30:26 UTC
From:
To:
To be clear, the time given by "w -t" for GNOME Terminal is the
expected one, i.e. the start time of GNOME Terminal.

But for the other terminals, I get the start time of the systemd
login session, even though the start time of the terminals is
available, as given by ps (the inode change time of the tty file
also seems to give it, possibly with a difference of one second,
but if the user does a chmod on it, the value changes, so that
it is not reliable).

Actually there is a systemd login session for GNOME Terminal.
It is just that the process does not appear.

BTW, according to

https://github.com/systemd/systemd/commit/bdb07fa5aca84cf6d092607e0e9d42f4bfeaa200

the value of $XDG_SESSION_ID should override the actual session
of the process (which may not be meaningful).

I don't know. I suspect that w tries to get session information from
systemd-logind, and that the output is correct only for GNOME Terminal
just because of the particular settings concerning GNOME Terminal and
that w thinks that the terminal does not have an associated login
session. But w should not do that anyway. In terminal mode, the start
time should always by the value given in the processus table.