Skip to content

Commit

Permalink
Don't try to shutdown() a pty
Browse files Browse the repository at this point in the history
shutdown() of a pty doesn't work (ENOTSOCK), so we should close
it instead.

This will ensure that PTY controlling terminals are closed when a
session exits, including when multiple sessions run over a single SSH
connection.  In the normal case of a single session, the PTY controlling
terminal would be closed when the Dropbear server process exits anyway.

This possibly fixes #264 on github

It is possible that there could be subtle changes to PTY flushing
behaviour, though nothing caught by tests at present.
  • Loading branch information
mkj committed Dec 9, 2023
1 parent 75c610d commit e28ba1b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ struct Channel {
int errfd; /* used like writefd or readfd, depending if it's client or server.
Doesn't exactly belong here, but is cleaner here */
int bidir_fd; /* a boolean indicating that writefd/readfd are the same
file descriptor (bidirectional), such as a network socket or PTY.
That is handled differently when closing FDs */
file descriptor (bidirectional), such as a network sockets.
That is handled differently when closing FDs. Is only
applicable to sockets (which can be used with shutdown()) */
circbuffer *writebuf; /* data from the wire, for local consumption. Can be
initially NULL */
circbuffer *extrabuf; /* extended-data for the program - used like writebuf
Expand Down
2 changes: 1 addition & 1 deletion src/svr-chansession.c
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ static int ptycommand(struct Channel *channel, struct ChanSess *chansess) {
channel->readfd = chansess->master;
/* don't need to set stderr here */
ses.maxfd = MAX(ses.maxfd, chansess->master);
channel->bidir_fd = 1;
channel->bidir_fd = 0;

setnonblocking(chansess->master);

Expand Down

0 comments on commit e28ba1b

Please sign in to comment.