From: Karel Zak Date: Fri, 22 Nov 2019 11:34:45 +0000 (+0100) Subject: scriptlive: terminate session at end of the log X-Git-Tag: v2.35-rc1~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=95d255a81997a298ec802566fe65c8951558907e;p=thirdparty%2Futil-linux.git scriptlive: terminate session at end of the log We need a proper way how to inform child (shell) that the game is over. It seems the best is to send EOF to child rather than immediately break PTY mainloop where we have poll(), because shell can still produce data etc. Signed-off-by: Karel Zak --- diff --git a/include/pty-session.h b/include/pty-session.h index 30932d0351..798f606b82 100644 --- a/include/pty-session.h +++ b/include/pty-session.h @@ -100,5 +100,6 @@ void ul_pty_set_mainloop_time(struct ul_pty *pty, struct timeval *tv); int ul_pty_get_childfd(struct ul_pty *pty); void ul_pty_wait_for_child(struct ul_pty *pty); pid_t ul_pty_get_child(struct ul_pty *pty); +void ul_pty_write_eof_to_child(struct ul_pty *pty); #endif /* UTIL_LINUX_PTY_H */ diff --git a/lib/pty-session.c b/lib/pty-session.c index 87d8e58b5e..8017d9f4d5 100644 --- a/lib/pty-session.c +++ b/lib/pty-session.c @@ -289,7 +289,7 @@ static int write_to_child(struct ul_pty *pty, char *buf, size_t bufsz) * maintains master+slave tty stuff within the session. Use pipe to write to * pty and assume non-interactive (tee-like) behavior is NOT well supported. */ -static void write_eof_to_child(struct ul_pty *pty) +void ul_pty_write_eof_to_child(struct ul_pty *pty) { unsigned int tries = 0; struct pollfd fds[] = { @@ -596,7 +596,7 @@ int ul_pty_proxy_master(struct ul_pty *pty) DBG(IO, ul_debugobj(pty, " ignore FD")); pfd[i].fd = -1; if (i == POLLFD_STDIN) { - write_eof_to_child(pty); + ul_pty_write_eof_to_child(pty); DBG(IO, ul_debugobj(pty, " ignore STDIN")); } } diff --git a/term-utils/scriptlive.c b/term-utils/scriptlive.c index b7abe36106..29d16557c0 100644 --- a/term-utils/scriptlive.c +++ b/term-utils/scriptlive.c @@ -108,6 +108,11 @@ static int process_next_step(struct scriptlive *ss) struct timeval *delay; rc = replay_get_next_step(ss->setup, "I", &ss->step); + if (rc == 1) { + ul_pty_write_eof_to_child(ss->pty); + rc = 0; + break; + } if (rc) break;