muxed client changes

Howard Chu hyc at
Thu Jun 17 10:33:45 EST 2010

Howard Chu wrote:
> Howard Chu wrote:
>> Everything should work exactly as before when connecting to an unpatached
>> server. With a patched server and patched shell you'll have local editing plus
>> command history. I'm still working out how to pass-thru the command completion
>> bits.
> Ugh. Except that this only works well for a single client; if you mux another
> session in everything breaks. The GNU readline library assumes it's only
> working with one display in one process; it doesn't work well trying to mux it
> across multiple ttys. Is there a particular reason why the muxing code didn't
> just relay the session data from the master to the slave client, rather than
> passing file descriptors to the master and having it write directly to the
> slave's tty? I guess it saves on memory copies, but it also limits the other
> clients.

I've tweaked the mux framework to solve this:

Date:   Wed Jun 16 17:22:11 2010 -0700

     Add a new channel type for muxed clients.

     Previously the slave client process did nothing but wait for an
     exit message from the master. Now, it handles all terminal input
     and forwards the data to the master. This input is performed in
     the new SSH_CHANNEL_MUX_OPEN channel type in the slave process.
     The master still runs a regular SSH_CHANNEL_OPEN session to the
     remote host on behalf of the slave, and it still writes all of
     this channel output directly to the slave tty, but it no longer
     does any reading, and the channel's rfd is set to -1.

     Splitting things apart like this allows each session to operate
     their ttys independently without mixing up mode changes. It also
     allows the slave client to suspend itself on demand.

     Further additions to the mux framework include a WINCH message;
     the slave client handles its own SIGWINCH events and sends the
     data to the master, which forwards it to the remote host. This
     eliminates the need for the master to poll every session with
     TIOCGWINSZ and send size updates for every session at once.

     Also, to support readline, the master session has an output filter
     to search for a commandline prompt on the tail of the incoming
     data. This also gets sent from the master to the slave process.

     Likewise, tty-change messages received for the session are forwarded
     from the master to the slave process.

Something else I just noticed; the escape filter was broken anyway when muxed 
clients were around because it depended on a single last_was_cr flag, even 
though it could be processing input for many sessions in an interleaved order. 
As such it would fail to detect an escape character in a lot of situations 
where it should have seen it. That's fixed by splitting things up this way too.

Patches available here:

  channels.c   |   53 +++++++-----
  channels.h   |    4 +-
  clientloop.c |  199 ++++++++++++++++++++++++++++++++++++-------
  clientloop.h |    9 ++
  mux.c        |  271 +++++++++++++++++++++++++++++++++++++++++++++++++++-------
  packet.c     |   12 +++
  packet.h     |    4 +-
  ttymodes.c   |   35 ++++----

   -- Howard Chu
   CTO, Symas Corp. 
   Director, Highland Sun
   Chief Architect, OpenLDAP

More information about the openssh-unix-dev mailing list