From b102addf9f12f314f03834b18a1114229ba65b04 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Thu, 7 Mar 2024 11:44:42 +0100 Subject: [PATCH] [fg] Try to send CONT signal only from the master instance. Refs #287 --- src/osdep/signals.c | 23 ++++++++++++----------- src/terminal/terminal.c | 7 +++++++ src/terminal/terminal.h | 1 + 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/osdep/signals.c b/src/osdep/signals.c index bb9c3aa0..8bb0d0c3 100644 --- a/src/osdep/signals.c +++ b/src/osdep/signals.c @@ -73,21 +73,22 @@ static void sig_tstp(struct terminal *term) { #ifdef SIGSTOP - pid_t newpid; pid_t pid = getpid(); block_itrm(); #if defined (SIGCONT) && defined(SIGTTOU) - newpid = fork(); - if (!newpid) { - sleep(1); - kill(pid, SIGCONT); - /* Use _exit() rather than exit(), so that atexit - * functions are not called, and stdio output buffers - * are not flushed. Any such things must have been - * inherited from the parent process, which will take - * care of them when appropriate. */ - _exit(0); + if (pid == master_pid) { + pid_t newpid = fork(); + if (!newpid) { + sleep(1); + kill(pid, SIGCONT); + /* Use _exit() rather than exit(), so that atexit + * functions are not called, and stdio output buffers + * are not flushed. Any such things must have been + * inherited from the parent process, which will take + * care of them when appropriate. */ + _exit(0); + } } #endif raise(SIGSTOP); diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index e8f68920..2a415762 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -54,6 +54,8 @@ INIT_LIST_OF(struct terminal, terminals); struct hash *temporary_files; static void check_if_no_terminal(void); +pid_t master_pid = 0; + void clean_temporary_files(void) { @@ -188,6 +190,11 @@ init_term(int fdin, int fdout) term->fdin = fdin; term->fdout = fdout; term->master = (term->fdout == get_output_handle()); + + if (term->master) { + master_pid = getpid(); + } + term->blocked = -1; get_terminal_name(name + 9); diff --git a/src/terminal/terminal.h b/src/terminal/terminal.h index 0c91ac31..53c62f56 100644 --- a/src/terminal/terminal.h +++ b/src/terminal/terminal.h @@ -14,6 +14,7 @@ struct option; struct terminal_screen; struct terminal_interlink; +extern pid_t master_pid; /** The terminal type, meaningful for frames (lines) drawing. */ enum term_mode_type {