Просмотр исходного кода

Fix client hanging on stdin closing by external cause

Serj Kalichev 1 год назад
Родитель
Сommit
a45213c0d9
1 измененных файлов с 9 добавлено и 4 удалено
  1. 9 4
      bin/klish/interactive.c

+ 9 - 4
bin/klish/interactive.c

@@ -311,18 +311,24 @@ bool_t cmd_incompleted_ack_cb(ktp_session_t *ktp, const faux_msg_t *msg, void *u
 static bool_t stdin_cb(faux_eloop_t *eloop, faux_eloop_type_e type,
 	void *associated_data, void *udata)
 {
+	bool_t rc = BOOL_TRUE;
 	ctx_t *ctx = (ctx_t *)udata;
 	ktp_session_state_e state = KTP_SESSION_STATE_ERROR;
+	faux_eloop_info_fd_t *info = (faux_eloop_info_fd_t *)associated_data;
 
 	if (!ctx)
 		return BOOL_FALSE;
 
+	// Some errors or fd is closed so stop session
+	if (info->revents & (POLLHUP | POLLERR | POLLNVAL))
+		rc = BOOL_FALSE;
+
 	state = ktp_session_state(ctx->ktp);
 
 	// Standard klish command line
 	if (state == KTP_SESSION_STATE_IDLE) {
 		tinyrl_read(ctx->tinyrl);
-		return BOOL_TRUE;
+		return rc;
 	}
 
 	// Interactive command
@@ -337,7 +343,7 @@ static bool_t stdin_cb(faux_eloop_t *eloop, faux_eloop_type_e type,
 			if (bytes_readed != sizeof(buf))
 				break;
 		}
-		return BOOL_TRUE;
+		return rc;
 	}
 
 	// Here the situation when input is not allowed. Remove stdin from
@@ -348,9 +354,8 @@ static bool_t stdin_cb(faux_eloop_t *eloop, faux_eloop_type_e type,
 	// Happy compiler
 	eloop = eloop;
 	type = type;
-	associated_data = associated_data;
 
-	return BOOL_TRUE;
+	return rc;
 }