0

I'm currently using termios to set up a serial console over USB for a Linux machine. I'm running into a problem however that the serial console's terminal is defaulting to vt220. I would like to use vt100 so I can get color. Once I'm in the serial console, setting the TERM environment variable to vt100 does work, however I would like the terminal to default to vt100 instead of vt220. Is there a way to do this with termios? See the code below for how I am setting up the tty device.

struct termios modes;

/* Initialize the remote line.
 */
if (tcgetattr(rmt_fd, &modes) < 0) {
    return -1;
}

modes.c_iflag = BRKINT | ISTRIP;
modes.c_oflag = 0;
modes.c_lflag = 0;
modes.c_cc[VMIN] = 1;
modes.c_cc[VTIME] = 0;

return tcsetattr(rmt_fd, TCSANOW, &modes);
DrinkaZ
  • 79
  • 1
  • 4
  • Short answer - no. – fpmurphy Oct 24 '22 at 15:54
  • @fpmurphy Not sure if this makes sense as I'm still learning about pty's, but if I put a pty in between the tty and stdout, would that theoretically work? So the tty would write to the pty and stdout would read from the pty and vice versa. – DrinkaZ Oct 24 '22 at 16:01
  • I presume you are attaching to the serial UART under linux by running your program in a terminal window. Your program attaches to the USB device and relays the data. The terminal emulator program is (e.g. `xterm` or `gnome-terminal`). If it's defaulting to vt220 (unusual as the default usually _is_ vt100), then you'll need to tell the terminal emulator program to default to vt100 either by command line option or config file option before firing it up. Maybe just use `xterm` (e.g.) `xterm -e myprogram` – Craig Estey Oct 24 '22 at 16:25
  • Is the console's getty service set up by systemd's `serial-getty@` template? When you log in to the console, what does `systemctl list-units 'serial-getty*'` show? You can configure the environment for all `serial-getty@` services by creating `/etc/systemd/system/serial-getty@.service.d/override.conf` containing the lines `[Service]` `Environment="TERM=vt100"`. To configure a single `serial-getty@` service for a particular serial port (say `ttyS0`), create `/etc/systemd/system/serial-getty@ttyS0.service.d/override.conf` instead. – Ian Abbott Oct 24 '22 at 17:08
  • The default `TERM` for serial TTYs changed from `vt102` to `vt220` in systemd v219 ([commit 3c4230a5afb27faec2176d4642c0e2e145971b5c](https://cgit.freedesktop.org/systemd/systemd/commit/?id=3c4230a5afb27faec2176d4642c0e2e145971b5c)). – Ian Abbott Oct 24 '22 at 17:24
  • @IanAbbott this worked but I was hoping there was a way to do this from the local side. Sadly does not seem to be possible. – DrinkaZ Oct 24 '22 at 17:44
  • @DrinkaZ Not over serial, no. Network terminal protocols such as telnet and ssh allow the client to pass the local TERM environment variable to the server, which it will use when creating the login session. – Ian Abbott Oct 24 '22 at 17:50
  • "*See the code below for how I am setting up the tty device.*" -- Your code make no sense, and does not follow best practices. See [Setting Terminal Modes Properly](https://www.gnu.org/software/libc/manual/html_node/Setting-Modes.html) and [Serial Programming Guide for POSIX Operating Systems](http://www.cmrr.umn.edu/~strupp/serial.html) – sawdust Oct 25 '22 at 06:23
  • @sawdust can you explain what doesn’t make sense? This is just a snippet of my initial setup. – DrinkaZ Oct 25 '22 at 21:21
  • If you studied the two articles, then it should be obvious that your termios initialization is low quality, nonfunctional (e.g. CREAD is not enabled), and ambiguous (e.g. no baudrate, framing, or line settings are specified). Yet you seem to claim that it is working for you! Although the references to "remote line" and "rmt_fd" are confusing because you can actually only configure the serial terminal directly attached to the local CPU – sawdust Oct 25 '22 at 22:27

0 Answers0