diff --git a/ssh.c b/ssh.c index 421315e4..d74a0ff2 100644 --- a/ssh.c +++ b/ssh.c @@ -865,6 +865,13 @@ bool ssh_is_bare(Ssh *ssh) return ssh->backend.vt->protocol == PROT_SSHCONN; } +/* Dummy connlayer must provide ssh_sharing_no_more_downstreams, + * because it might be called early due to plink -shareexists */ +static void dummy_sharing_no_more_downstreams(ConnectionLayer *cl) {} +static const ConnectionLayerVtable dummy_connlayer_vtable = { + .sharing_no_more_downstreams = dummy_sharing_no_more_downstreams, +}; + /* * Called to set up the connection. * @@ -900,6 +907,7 @@ static char *ssh_init(const BackendVtable *vt, Seat *seat, ssh->bare_connection = (vt->protocol == PROT_SSHCONN); ssh->seat = seat; + ssh->cl_dummy.vt = &dummy_connlayer_vtable; ssh->cl_dummy.logctx = ssh->logctx = logctx; random_ref(); /* do this now - may be needed by sharing setup code */ diff --git a/ssh2connection.c b/ssh2connection.c index 1c9454cb..ecb421ea 100644 --- a/ssh2connection.c +++ b/ssh2connection.c @@ -1020,6 +1020,7 @@ static void ssh2_connection_process_queue(PacketProtocolLayer *ppl) s->mainchan = mainchan_new( &s->ppl, &s->cl, s->conf, s->term_width, s->term_height, s->ssh_is_simple, &s->mainchan_sc); + s->started = true; /* * Transfer data! @@ -1248,6 +1249,15 @@ static void ssh2_check_termination(struct ssh2_connection_state *s) if (s->persistent) return; /* persistent mode: never proactively terminate */ + if (!s->started) { + /* At startup, we don't have any channels open because we + * haven't got round to opening the main one yet. In that + * situation, we don't want to terminate, even if a sharing + * connection opens and closes and causes a call to this + * function. */ + return; + } + if (count234(s->channels) == 0 && !(s->connshare && share_ndownstreams(s->connshare) > 0)) { /* diff --git a/ssh2connection.h b/ssh2connection.h index f0afb676..d3bb240a 100644 --- a/ssh2connection.h +++ b/ssh2connection.h @@ -19,6 +19,7 @@ struct ssh2_connection_state { bool ssh_is_simple; bool persistent; + bool started; Conf *conf;