浏览代码

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;
 		}