C / Linux Programming: Pseudo-Terminals: how to redirect from current stdio to pty and redirect back after use

I am trying to create a simple remote control program where a user can connect to my small device and take over the current system of the system. For instance:

Boot the system from the console = serial port -> the client connects, redirects input / output to the socket

I have already redirected to the network part (after reading a lot of man pages. Man, I still haven’t rated these pages with man: D) using pty functions for Linux.

openpty () → grantpt () → unlockpt () -> the client connects, performs login_tty ()

My program then processes the master FD file and socket. However, I have a big problem: I do not know how to redirect the output back. I tried the following:

o hardcode opens a file with a serial port

o use open serial port file in login_tty ()

but it doesn’t work (something about process groups and is the leader of the process group after the first login_tty ()). Any suggestions or ideas?

Does login_tty () use the reverse function?

+3
source share
1 answer

This is very similar to what the “screen” does. You can study the code and imitate it: http://www.gnu.org/software/screen/

+1
source

Source: https://habr.com/ru/post/1771026/


All Articles