Skip to content

Commit

Permalink
Merge pull request #296 from smemsh/masterpid-forkonstart
Browse files Browse the repository at this point in the history
fix suspend in session master when fork_on_start
  • Loading branch information
rkd77 authored Apr 11, 2024
2 parents 5886cad + b2556aa commit 605f2d8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
13 changes: 11 additions & 2 deletions src/main/interlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,13 +518,15 @@ int
init_interlink(void)
{
int fd = connect_to_af_unix();
int pid;

if (fd != -1 || remote_session_flags) return fd;

parse_options_again();

if (get_opt_bool("ui.sessions.fork_on_start", NULL)) {

pid_t pid;

pid = fork();

if (pid == -1) return -1;
Expand All @@ -535,11 +537,18 @@ init_interlink(void)
for (i = 1; i <= (MAX_BIND_TRIES+2); ++i) {
fd = connect_to_af_unix();

if (fd != -1) return fd;
if (fd != -1) {
master_pid = pid;
return fd;
}
elinks_usleep(BIND_TRIES_DELAY * i);
}
return -1;
}
/* child */
#ifdef HAVE_GETPID
master_pid = getpid();
#endif
close_terminal_pipes();
}
bind_to_af_unix();
Expand Down
5 changes: 5 additions & 0 deletions src/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@

struct program program;

pid_t master_pid = 0;

static int ac;
static char **av;
static int init_b = 0;
Expand Down Expand Up @@ -193,6 +195,9 @@ init(void)
|| get_cmd_opt_bool("source")
|| (fd = init_interlink()) == -1) {

#ifdef HAVE_GETPID
master_pid = getpid();
#endif
parse_options_again();
init_b = 1;
init_modules(builtin_modules);
Expand Down
1 change: 1 addition & 0 deletions src/main/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct program {
};

extern struct program program;
extern pid_t master_pid;

void shrink_memory(int);
void parse_options_again(void);
Expand Down
2 changes: 1 addition & 1 deletion src/osdep/signals.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ sig_tstp(struct terminal *term)

block_itrm();
#if defined (SIGCONT) && defined(SIGTTOU)
if (master_pid) {
if (pid == master_pid) {
pid_t newpid = fork();
if (!newpid) {
int r;
Expand Down
8 changes: 0 additions & 8 deletions src/terminal/terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ 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 @@ -191,12 +189,6 @@ init_term(int fdin, int fdout)
term->fdout = fdout;
term->master = (term->fdout == get_output_handle());

#ifdef HAVE_GETPID
if (term->master) {
master_pid = getpid();
}
#endif

term->blocked = -1;

get_terminal_name(name + 9);
Expand Down

0 comments on commit 605f2d8

Please sign in to comment.