Discussion:
Odd w/who behavior for the last 12 years
(too old to reply)
Timur I. Bakeyev
2018-05-28 03:26:22 UTC
Permalink
Hi all!

Recently I was trying to fix UTMP logging support in Samba, which supposed
to add login entries for all authenticated Samba sessions, writing down
user, session ID and remote host into the UTMP database(s). It used to work
with Samba 3.x and FreeBSD 6/7, but got broken since then, apparently.

Fixing Samba code to support "new" utmpx.h API was easy, but, despite that
I couldn't see the active session in the "w" and "who" output. Still,
"last" was showing the session normally:

timur smb/3863840071 test-server1.local Fri May 25 14:20 - 14:37
(00:17)

Quick look into the source code brought me to this 12 y.o. commit:

https://svnweb.freebsd.org/base?view=revision&revision=155875
In wall and who, check that the utmp entry isn't stalled, as it is done in w.
Apparently with the new pts code stalled entries are printed, when they are
not with the BSD ptys.
Submitted by: Michal Mertl <mime at traveller dot cz>
That can be tracked down to the
https://docs.freebsd.org/cgi/getmsg.cgi?fetch=822832+0+/usr/local/www/mailindex/archive/2006/freebsd-current/20060205.freebsd-current

While for the "wall" this patch has sense, it's quite broken for the
"who"(and similar broken "fix" exists for "w").

First of all, both of those programs supposed to show information about ALL
active sessions on the given machine. From the top of my head, besides
"ssh" and other programs, that allocate ptys there is a bunch of other
programs that write their sessions into UTMP, namely: xdm/gdm, vsftpd(and
probably few other FTPDs), gnome-terminal(I wrote the BSD* code in
gnome-pty-helper) and Samba.

I'm pretty sure I miss some other software that also stores session info
into UTMP, but I hope my point is clear.

Next, while in 2006 ptmx/pts was pretty flanky, there was a large work done
by Rober Watson (
https://docs.freebsd.org/cgi/getmsg.cgi?fetch=324362+0+archive/2007/freebsd-current/20071209.freebsd-current)
and Ed Schouten (
https://docs.freebsd.org/cgi/getmsg.cgi?fetch=22996+0+archive/2008/freebsd-current/20080727.freebsd-current)
that should fix the issues with ghost ptys.

So I propose to remove the said patch(or make it verify only "pts/"
devices). any objections?

With regards,
Timur Bakeyev.
Ed Schouten
2018-06-06 09:36:29 UTC
Permalink
Hi Timur,
Post by Timur I. Bakeyev
So I propose to remove the said patch(or make it verify only "pts/"
devices). any objections?
Sounds good! Changes like the ones made in r155875 were simply
workarounds to deal with processes silly enough not to write
DEAD_PROCESS entries. Instead of patching up w, wall, who, etc. we
should spend effort to fix these problems at the root instead.

Be sure to cc me on code reviews!
--
Ed Schouten <***@nuxi.nl>
Nuxi, 's-Hertogenbosch, the Netherlands
Loading...