From 8deb45fc5682c3ac0903a3e2b947ceedcc4ab7d6 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 21 Sep 2020 12:51:02 +0200 Subject: [PATCH] script: kill child process on error The recent change in code improves main-pool on error, but we need to kill child process if it still running to avoid hang up in next waitpid(). Signed-off-by: Karel Zak --- lib/pty-session.c | 6 ++++++ term-utils/script.c | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/pty-session.c b/lib/pty-session.c index 4cf29d6dd..6d8ba4eb7 100644 --- a/lib/pty-session.c +++ b/lib/pty-session.c @@ -631,6 +631,12 @@ int ul_pty_proxy_master(struct ul_pty *pty) break; } + if (rc && pty->child && pty->child != (pid_t) -1 && !pty->delivered_signal) { + kill(pty->child, SIGTERM); + sleep(2); + kill(pty->child, SIGKILL); + } + pty_signals_cleanup(pty); DBG(IO, ul_debug("poll() done [signal=%d, rc=%d]", pty->delivered_signal, rc)); diff --git a/term-utils/script.c b/term-utils/script.c index c7f3250de..0a12dda4f 100644 --- a/term-utils/script.c +++ b/term-utils/script.c @@ -673,7 +673,6 @@ static int callback_log_stream_activity(void *data, int fd, char *buf, size_t bu ctl->outsz += ssz; - /* check output limit */ if (ctl->maxsz != 0 && ctl->outsz >= ctl->maxsz) { if (!ctl->quiet)