title: C/Linux Programming: Pseudo-Terminals: how to redirect from current stdio to pty and redirect back after usage
body: <p>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. For example:</p>
  
  <p>System boots with console=serial port
  --> client connects, redirect input/output to the socket</p>
  
  <p>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.</p>
  
  <p>openpty() -> grantpt() -> unlockpt()
  --> client connects, perform login_tty()</p>
  
  <p>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:</p>
  
  <p>o hardcode opening the serial port file</p>
  
  <p>o use the opened serial port file in login_tty()</p>
  
  <p>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?</p>
  
  <p>Does login_tty() have an "inverse" function of some sort?</p>