开发者

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

I'm trying to create a simple remote management program where a user can connect 开发者_JS百科to my little device and "take over" the current stdio of the system. For example:

System boots with console=serial port --> client connects, redirect input/output to the socket

I have already accomplished the redirection to network part (by reading through a lot of man pages. Man, I have never appreciated these man pages until now! :D) using the pty functionalities of Linux.

openpty() -> grantpt() -> unlockpt() --> client connects, perform login_tty()

My program then handles the monitoring of the master FD and the socket. However, I have a big problem: I don't know how to redirect the output back. I tried the following:

o hardcode opening the serial port file

o use the opened serial port file in login_tty()

but it doesn't seem to work (something about process groups and being the leader of the process group after performing the first login_tty()). Any suggestions or ideas?

Does login_tty() have an "inverse" function of some sort?


This sounds very much like what "screen" does. You could study the code and mimic it from there: http://www.gnu.org/software/screen/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜