]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
scriptlive: terminate session at end of the log
authorKarel Zak <kzak@redhat.com>
Fri, 22 Nov 2019 11:34:45 +0000 (12:34 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 22 Nov 2019 12:03:35 +0000 (13:03 +0100)
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>
include/pty-session.h
lib/pty-session.c
term-utils/scriptlive.c

index 30932d03515064f49f01ffc545a588367aef6aca..798f606b82055d82b82d403c581447170bdf348c 100644 (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 */
index 87d8e58b5eafd8ffd177bc2165bf5972970c4f09..8017d9f4d5461d9d03f4e4236541b4347b74eba7 100644 (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"));
                                        }
                                }
index b7abe361064a2b7f635b84567c1d2a5995bfb8c7..29d16557c0447937abdafaccfa066a913ae1ad9a 100644 (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;