Broadcast messages don’t appear on gnome-terminal, but appear on xterm

broadcastterminal

I'm curious about the behavior of broadcast messages by

$ sudo wall myfile

the message from myfile appears on all /dev/ttyN devices (the ones to which I can switch by pressing Ctrl+Alt+fN), it also appears on the xterm windows I have opened, but it doesn't appear on gnome-terminal (actually I use Linux Mint with MATE, so it's mate-terminal, but it is fork of gnome-terminal).

There's also interesting note if I run tmux in the xterm: I expected that the message would appear on all terminal sessions that are running in tmux (on all windows, and in each pane of each window), but actually the message appears just at current cursor position in the xterm window.

If I check current controlling terminal by calling tty, it reports different terminals for different windows in tmux: say, I have /dev/pts/11 in one tmux window and /dev/pts/12 in another one. But, broadcast message appears just once for each xterm window, not for each terminal session opened in tmux.

It seems to me that terminal emulator, when allocating pseudo-terminal, needs, like, "registering" it somewhere to make it able to receive broadcast messages, and so, xterm does it, but mate-terminal and tmux does not. But it sounds weird since pseudo-terminal is allocated by the kernel, so, it should be "registered" automatically everywhere it needs to be.

I'd be glad if someone explain how does it work and why the behavior is that (seemingly weird).

Best Answer

The terminals listed hints that the behavior is seen with Linux: The clues are in the manual page for wall (Solaris for instance is different):

wall displays a message, or the contents of a file, or otherwise its standard input, on the terminals of all currently logged in users.

Some sessions, such as wdm, that have in the beginning of utmp(5) ut_type data a ':' character will not get the message from wall. This is done to avoid write errors.

That is, wall uses the utmp data, looks for terminals in use (i.e., logged-in users), and writes to the associated device. Each line in the output of w shows a (possible) terminal, recorded by the terminal in the utmp file. For instance, I am ssh'd into a server and running screen while at the same time I logged into a console. Just for completeness, I ran xterm using the -ls (login-shell) option. Here is the output of w:

$ w
 19:53:15 up  4:08,  5 users,  load average: 0.00, 0.01, 0.05
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
tom      tty2                      19:48    5:11   0.04s  0.02s -tcsh
tom      pts/0    michener:S.0     15:51   13:18   0.35s  0.24s ssh -X thomas@b
tom      pts/2    michener:S.1     16:34    2.00s  0.14s  0.00s sh -c w
tom      pts/4    michener:S.3     15:52    3:59m  0.12s  0.00s /bin/sh /users/
tom      pts/3    localhost:10.0   19:53    7.00s  0.03s  0.03s -tcsh

and running wall writes to each of those TTY devices.

However, if the terminal does not write to the utmp file, it will not be listed — and wall will ignore it.

Now, some programs may have the feature compiled-in, but lack privileges to change it. That is why some programs are run with setgid to the "utmp" group. Other programs (such as xterm — or gnome-terminal) may use an external program that updates utmp on their behalf.

With gnome-terminal, the feature has been deprecated due to the mindset of the gnome developers that (a) users run on a local machine, where gdm handles login, and (b) consequently there's no distinction worth bothering about between login shells and non-login shells. That makes for some interesting bug reports:

Related Question