Reputation: 312
I would like to create a new pty session in Linux, like as gnome-terminal xterm and others do. Half of my task is working, I created a pty session with openpty, fork()-ed a process, child uses the slave FD, and the remaining process terminal attach to a network socket.
Through the network I can connect to "remote terminal", but it's not working correctly. There's no echo, and characters aren't sent after the enter is pressed (so I can't navigate in nano, mc, etc).
The termios struct's set up with cfmakeraw(struct termios)
.
The Question: what is the default termios settings in a default session like in gnome-terminal and others.
Upvotes: 0
Views: 2271
Reputation: 1
The easiest way to do this on your local machine is by opening a fresh terminal and running the following code:
static struct termios tty;
tcgetattr(0, &tty);
printf("0x%x\n", tty.c_iflag);
printf("0x%x\n", tty.c_oflag);
printf("0x%x\n", tty.c_cflag);
printf("0x%x\n", tty.c_lflag);
Which on OSX at time of writing gave me:
0x6b02
0x3
0x4b00
0x200005cb
When I use these values to construct or repair a terminal it works great, e.g.
void reset_term()
{
static struct termios Otty, Ntty;
tcgetattr(0, &Otty);
Ntty = Otty;
Ntty.c_iflag = 0x6b02;
Ntty.c_oflag = 0x3;
Ntty.c_cflag = 0x4b00;
Ntty.c_lflag = 0x200005cb;
tcsetattr(0, TCSAFLUSH, &Ntty);
}
Upvotes: 0
Reputation: 753775
If your standard input, standard output or standard error is going to your terminal and is sane, you could copy the settings from your terminal to your pty using tcgetattr()
and tcsetattr()
.
struct termios ttyset;
if (tcgetattr(FILE_STDERR, &ttyset) != 0)
...handle error - maybe try stdout or stdin...
if (tcsetattr(pty_fd, TCSANOW, &ttyset) != 0)
...handle error...
Basically, this assumes you have a good set of terminal settings to start with and copies the setting from FILE_STDERR
to pty_fd
(which is assumed to be a file descriptor for the slave side of your pseudo-tty).
Of course, you could capture the settings a considerable time before you use them to initialize the pseudo-tty, even though they are shown as adjacent operations in the code fragment above.
Upvotes: 0
Reputation:
Pass NULL
as the struct termios *
argument to openpty()
(or forkpty()
, which you should look into!), and the resulting defaults should be reasonable for an interactive terminal.
Upvotes: 2