|  | @@ -389,7 +389,7 @@ static void ssh_initiate_connection_close(Ssh ssh)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  void ssh_remote_error(Ssh ssh, const char *fmt, ...)
 | 
	
		
			
				|  |  |  {
 | 
	
		
			
				|  |  | -    if (ssh->base_layer) {
 | 
	
		
			
				|  |  | +    if (ssh->base_layer || !ssh->session_started) {
 | 
	
		
			
				|  |  |          GET_FORMATTED_MSG;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          /* Error messages sent by the remote don't count as clean exits */
 | 
	
	
		
			
				|  | @@ -407,7 +407,7 @@ void ssh_remote_error(Ssh ssh, const char *fmt, ...)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  void ssh_remote_eof(Ssh ssh, const char *fmt, ...)
 | 
	
		
			
				|  |  |  {
 | 
	
		
			
				|  |  | -    if (ssh->base_layer) {
 | 
	
		
			
				|  |  | +    if (ssh->base_layer || !ssh->session_started) {
 | 
	
		
			
				|  |  |          GET_FORMATTED_MSG;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          /* EOF from the remote, if we were expecting it, does count as
 | 
	
	
		
			
				|  | @@ -430,7 +430,7 @@ void ssh_remote_eof(Ssh ssh, const char *fmt, ...)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  void ssh_proto_error(Ssh ssh, const char *fmt, ...)
 | 
	
		
			
				|  |  |  {
 | 
	
		
			
				|  |  | -    if (ssh->base_layer) {
 | 
	
		
			
				|  |  | +    if (ssh->base_layer || !ssh->session_started) {
 | 
	
		
			
				|  |  |          GET_FORMATTED_MSG;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          ssh->exitcode = 128;
 | 
	
	
		
			
				|  | @@ -447,7 +447,7 @@ void ssh_proto_error(Ssh ssh, const char *fmt, ...)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  void ssh_sw_abort(Ssh ssh, const char *fmt, ...)
 | 
	
		
			
				|  |  |  {
 | 
	
		
			
				|  |  | -    if (ssh->base_layer) {
 | 
	
		
			
				|  |  | +    if (ssh->base_layer || !ssh->session_started) {
 | 
	
		
			
				|  |  |          GET_FORMATTED_MSG;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          ssh->exitcode = 128;
 | 
	
	
		
			
				|  | @@ -464,7 +464,7 @@ void ssh_sw_abort(Ssh ssh, const char *fmt, ...)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  void ssh_user_close(Ssh ssh, const char *fmt, ...)
 | 
	
		
			
				|  |  |  {
 | 
	
		
			
				|  |  | -    if (ssh->base_layer) {
 | 
	
		
			
				|  |  | +    if (ssh->base_layer || !ssh->session_started) {
 | 
	
		
			
				|  |  |          GET_FORMATTED_MSG;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          /* Closing the connection due to user action, even if the
 | 
	
	
		
			
				|  | @@ -509,7 +509,9 @@ static void ssh_closing(Plug plug, const char *error_msg, int error_code,
 | 
	
		
			
				|  |  |  			int calling_back)
 | 
	
		
			
				|  |  |  {
 | 
	
		
			
				|  |  |      Ssh ssh = FROMFIELD(plug, struct ssh_tag, plugvt);
 | 
	
		
			
				|  |  | -    if (ssh->bpp) {
 | 
	
		
			
				|  |  | +    if (error_msg) {
 | 
	
		
			
				|  |  | +        ssh_remote_error(ssh, "Network error: %s", error_msg);
 | 
	
		
			
				|  |  | +    } else if (ssh->bpp) {
 | 
	
		
			
				|  |  |          ssh->bpp->input_eof = TRUE;
 | 
	
		
			
				|  |  |          queue_idempotent_callback(&ssh->bpp->ic_in_raw);
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -974,9 +976,6 @@ static const SessionSpecial *ssh_get_specials(Backend *be)
 | 
	
		
			
				|  |  |      if (ssh->base_layer)
 | 
	
		
			
				|  |  |          ssh_ppl_get_specials(ssh->base_layer, ssh_add_special, &ctx);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    if (!ssh->specials)
 | 
	
		
			
				|  |  | -        return NULL;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      if (ctx.specials) {
 | 
	
		
			
				|  |  |          /* If the list is non-empty, terminate it with a SS_EXITMENU. */
 | 
	
		
			
				|  |  |          ssh_add_special(&ctx, NULL, SS_EXITMENU, 0);
 |