Arch Linux, Serial Console; Garbled messages
A couple of years ago now I scored a serial console, specifically a Link MC-3 which is a rebadged Wyse 60 (or thereabouts) which is itself a knock-off VT-220. I love it to death, and relish any opportunity to drag it out and do something with it.
So the other day I was going to use it to reinstall FreeBSD on my time server, but couldn’t find a cable for it, so I built a new one… and in the process of testing that, I found that when I enabled getty (well, the systemd equivalent of it anyway, and in case future me is looking at this post going “what did you know?!”, the command to do this is systemctl start serial-getty@ttyUSB0.service if the serial device is /dev/ttyUSB0) on my Linux machine, I get some weird messages that look somewhat reminiscent of auditd style messages:
3008;start=<some uuid>;user=root;hostname=fwaggle-laptop;machineid=<some uuid>;bootid=<some uuid>;pid=1234;type=command;cwd=/home/fwaggle
There’s a bunch of these, before and after every command, before and during a login, everywhere. I put up with them and ended up doing something else, and today during lunch I happened to take another look, and managed to turn up a handful of GitHub issues about it, leading to the culprit: systemd itself!
They’re OSC “context” messages, with the idea being your shell will quietly eat them and be able to do all sorts of things at the presentation level, like showing which commands ran as root, and one of the more interesting example uses is being able to right click on a command’s output and kill the process that generated it. As it’s in-band signalling, it does bring up interesting ideas about how one could spoof it for interesting tricks, but I am not aware of anything just yet that uses it.
I find it pretty obvious that the argument that any VT-100 or ANSI-capable terminal will ignore these messages doesn’t hold water, but it was comforting to see that I wasn’t alone, why someone else had the same issue just three weeks ago!
The solution is pretty easy to do, though not exactly elegant. First, run systemctl edit serial-getty\@.service, which will spawn your editor (hope your $EDITOR or $VISUAL is set correctly). I add this to the file:
[Service]
Environment=TERM=dumb
This tells systemd your terminal is “dumb”, and does not support all the OSC messages. Upon running systemctl restart serial-getty@ttyUSB0.service the problem has gone away! Unfortunately so has a bunch of other shit, like the ability for the shell to clear the screen, move the cursor, and so on. Baby, bathwater, bye. Purists may argue this relegates you back to the proper early terminal days, but I have VT-220 capability I would like to use it, thank you very much.
I haven’t found an acceptable solution to this. You can run export TERM=vt220 in your shell after login, but I would like a way to automate it.
Apparently a more permanent fix is to remove /etc/profile.d/80-systemd-osc-context.sh and create an empty /etc/tmpfiles.d/20-systemd-osc-context.conf file to stop the former being recreated, but I’m not sure what else that will break in the future and this is rather rare an occurrence for me.
