소스 검색

Fixed klish pipe hanging when filter exits before main command.

The example is "cat long_file | head -n 20". The "head" exits
after getting 20 lines but "cat" hangs. It try to write to the
pipe. The klishd had a copy of pipe read end opened. Close such
descriptor on command sequence end.
Serj Kalichev 5 달 전
부모
커밋
13c1935b41
1개의 변경된 파일8개의 추가작업 그리고 0개의 파일을 삭제
  1. 8 0
      klish/ksession/kexec.c

+ 8 - 0
klish/ksession/kexec.c

@@ -716,11 +716,19 @@ static bool_t exec_action_sequence(const kexec_t *exec, kcontext_t *context,
 		// Is it end of ACTION sequence?
 		if (!iter) {
 			kcontext_set_done(context, BOOL_TRUE);
+
 			// Close the stdout of finished ACTION sequence to inform
 			// process next in pipe about EOF. Else filter will not
 			// stop at all.
 			close(kcontext_stdout(context));
 			kcontext_set_stdout(context, -1);
+
+			// Close the stdin of finished ACTION sequence to inform
+			// process previous in pipe. Else previous command will
+			// try to write to the pipe continously.
+			close(kcontext_stdin(context));
+			kcontext_set_stdin(context, -1);
+
 			return BOOL_TRUE;
 		}