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 <kzak@redhat.com>
This commit is contained in:
Karel Zak 2019-11-22 12:34:45 +01:00
parent f896aef36b
commit 95d255a819
3 changed files with 8 additions and 2 deletions

View File

@ -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 */

View File

@ -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"));
}
}

View File

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