简体   繁体   English

C / Linux编程:伪终端:如何从当前stdio重定向到pty并在使用后重定向

[英]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 to my little device and "take over" the current stdio of the system. 我正在尝试创建一个简单的远程管理程序,用户可以连接到我的小设备并“接管”系统的当前stdio。 For example: 例如:

System boots with console=serial port --> client connects, redirect input/output to the socket 系统引导与console =串口 - >客户端连接,将输入/输出重定向到套接字

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. 我已经完成了重定向到网络部分(通过阅读很多手册页。男,我从来没有意识到这些手册页直到现在!:D)使用Linux的pty功能。

openpty() -> grantpt() -> unlockpt() --> client connects, perform login_tty() openpty() - > grantpt() - > unlockpt() - >客户端连接,执行login_tty()

My program then handles the monitoring of the master FD and the socket. 然后我的程序处理主FD和套接字的监视。 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硬编码打开串口文件

o use the opened serial port file in login_tty() o使用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()). 但它似乎不起作用(关于进程组并在执行第一个login_tty()之后成为进程组的领导者)。 Any suggestions or ideas? 有什么建议或想法吗?

Does login_tty() have an "inverse" function of some sort? login_tty()是否具有某种“反向”功能?

This sounds very much like what "screen" does. 这听起来非常像“屏幕”。 You could study the code and mimic it from there: http://www.gnu.org/software/screen/ 您可以从那里学习代码并模仿它: http//www.gnu.org/software/screen/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM