Skip to content

Commit

Permalink
[fg] Try to send CONT signal only from the master instance. Refs #287
Browse files Browse the repository at this point in the history
  • Loading branch information
rkd77 committed Mar 7, 2024
1 parent 9c04585 commit b102add
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/osdep/signals.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions src/terminal/terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/terminal/terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b102add

Please sign in to comment.