summaryrefslogtreecommitdiffstats
path: root/term-utils/script.c
diff options
context:
space:
mode:
authorKarel Zak2017-09-08 09:48:29 +0200
committerKarel Zak2017-09-08 09:48:29 +0200
commit2e7a92270114cc652ea090251a374e917adb7a72 (patch)
tree384be775e19047b3d4c171d5e51eaf39e2eb304e /term-utils/script.c
parentlsblk: small man page change in return codes description (diff)
downloadkernel-qcow2-util-linux-2e7a92270114cc652ea090251a374e917adb7a72.tar.gz
kernel-qcow2-util-linux-2e7a92270114cc652ea090251a374e917adb7a72.tar.xz
kernel-qcow2-util-linux-2e7a92270114cc652ea090251a374e917adb7a72.zip
script: support sig{stop/cont}
* call wait() only when child exited * suspend all session (including script master process) when child get SIGSTOP and send SIGCONT to child when master process resume This allows to suspend all session and later use "fg" shell command to resume. $ ps af 14722 pts/1 Ss 0:00 bash 4870 pts/1 S+ 0:00 \_ ./script 4871 pts/6 Ss+ 0:00 \_ bash -i $ kill -SIGSTOP 4871 and script session on another terminal: $ script Script started, file is typescript $  [1]+ Stopped ./script $ fg 1 ./script ... session again usable ... ^D Script done, file is typescript Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'term-utils/script.c')
-rw-r--r--term-utils/script.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/term-utils/script.c b/term-utils/script.c
index ffc7017b9..604e47a46 100644
--- a/term-utils/script.c
+++ b/term-utils/script.c
@@ -403,8 +403,15 @@ static void handle_signal(struct script_control *ctl, int fd)
switch (info.ssi_signo) {
case SIGCHLD:
DBG(SIGNAL, ul_debug(" get signal SIGCHLD"));
- wait_for_child(ctl, 0);
- ctl->poll_timeout = 10;
+ if (info.ssi_code == CLD_EXITED) {
+ wait_for_child(ctl, 0);
+ ctl->poll_timeout = 10;
+ } else if (info.ssi_status == SIGSTOP && ctl->child) {
+ DBG(SIGNAL, ul_debug(" child stop by SIGSTOP -- stop parent too"));
+ kill(getpid(), SIGSTOP);
+ DBG(SIGNAL, ul_debug(" resume"));
+ kill(ctl->child, SIGCONT);
+ }
return;
case SIGWINCH:
DBG(SIGNAL, ul_debug(" get signal SIGWINCH"));