0

I need to save the terminal attributes (tcgetattr), set them to something that will block terminal echoing etc. (calling tcsetattr), and then later, after doing things with the framebuffer device /dev/fb0, restore the original attributes (calling tcsetattr).

I'm finding that the second call to tcsetattr always fails with an I/O error i.e. errno == EIO.

Is there a special trick to doing this?

struct termios originaltermios;
struct termios newtermios;
tcgetattr(console_fd, &originaltermios);
// 
newtermios = originaltermios;
tcsdrain(console_fd);
// (change newtermios here)
tcsetattr(console_fd, TCSANOW, &newtermios);
// ... do some stuff for 10-20 seconds with /dev/fd0
if (tcsetattr(console_fd, TCSANOW, &originaltermios)) {
    perror("tcsetattr"); // EIO
}
    new_termios.c_lflag &= ~ECHO;
    new_termios.c_lflag &= ~ISIG;
    new_termios.c_lflag &= ~ICANON;
    new_termios.c_lflag &= ~IEXTEN;
    new_termios.c_iflag &= ~ISTRIP;
    new_termios.c_iflag &= ~ICRNL;
    new_termios.c_iflag &= ~INLCR;
    new_termios.c_iflag &= ~IGNCR;
    new_termios.c_iflag &= ~BRKINT;
    new_termios.c_iflag &= ~(IXON|IXOFF);
    new_termios.c_cc[VMIN] = 0;
    new_termios.c_cc[VTIME] = 0;
s_question
  • 21
  • 2
  • 1
    Where `console_fd` came from? Do first `tcsetattr()` fail? Do `tcgetattr()` fail? What changes performed on `newtermios`? Please provide minimal reproducible example. – dimich Jun 10 '23 at 04:07
  • console_fd = open("/dev/console", O_NONBLOCK); – s_question Jun 10 '23 at 20:50
  • The first tcsetattr doesn't fail. It's just the second one that fails. This happens after I have set the console from graphics mode to text mode. – s_question Jun 10 '23 at 20:51
  • The goal of the above alterations to the termios is to allow the program to take over the framebuffer console and not see characters echo'd to the screen, and to read characters in a raw state. – s_question Jun 10 '23 at 21:11
  • `/dev/console` is a system console where kernel print logs. Maybe you want `/dev/tty`? How is it related to framebuffer device? You mentioned framebuffer but there is `/dev/fd0` in code. Did you mean `/dev/fb0` or `/dev/fd/0`? Can't reproduce using provided code neither with `/dev/console` nor with `/dev/tty`: both `tcsetattr()` return success. – dimich Jun 11 '23 at 00:16

0 Answers0