From 2dcac411a8149b9db4e3837316a407b528df30e9 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Thu, 21 May 2020 16:53:43 +0200 Subject: [PATCH] [sessions] New option ui.sessions.fork_on_start Default value of this bool option is 0. Nothing changes in behaviour since 0.13.1. If you set it to 1, one more process will be started. This main process will handle only interlink connections, while other processes will be slaves to it. This will allow to exit first started elinks session without breaking others. --- src/config/options.inc | 25 +++++++++++++++---------- src/main/interlink.c | 27 +++++++++++++++++---------- src/main/main.c | 34 +++++++++++++++++++++------------- src/main/main.h | 1 + 4 files changed, 54 insertions(+), 33 deletions(-) diff --git a/src/config/options.inc b/src/config/options.inc index e63ad694..2e5b3b46 100644 --- a/src/config/options.inc +++ b/src/config/options.inc @@ -1422,10 +1422,11 @@ static union option_info config_options_info[] = { "sessions", OPT_SORT, N_("Sessions settings.")), - INIT_OPT_BOOL("ui.sessions", N_("Keep session active"), - "keep_session_active", 0, 0, - N_("Keep the session active even if the last terminal " - "exits.")), + INIT_OPT_BOOL("ui.sessions", N_("Auto restore session"), + "auto_restore", 0, 0, + N_("Automatically restore the session at start.\n" + "\n" + "This feature requires bookmark support.")), INIT_OPT_BOOL("ui.sessions", N_("Auto save session"), "auto_save", 0, 0, @@ -1433,12 +1434,6 @@ static union option_info config_options_info[] = { "\n" "This feature requires bookmark support.")), - INIT_OPT_BOOL("ui.sessions", N_("Auto restore session"), - "auto_restore", 0, 0, - N_("Automatically restore the session at start.\n" - "\n" - "This feature requires bookmark support.")), - INIT_OPT_STRING("ui.sessions", N_("Auto save and restore session folder name"), "auto_save_foldername", 0, "Auto saved session", N_("Name of the bookmarks folder used for auto saving and " @@ -1447,6 +1442,11 @@ static union option_info config_options_info[] = { "\n" "This only makes sense with bookmark support.")), + INIT_OPT_BOOL("ui.sessions", N_("Fork on start"), + "fork_on_start", 0, 0, + N_("Fork on start to let other terminals function even " + "if the first terminal exits.")), + INIT_OPT_STRING("ui.sessions", N_("Homepage URI"), "homepage", 0, WWW_HOME_URL, N_("The URI to load either at startup time when no URI was " @@ -1454,6 +1454,11 @@ static union option_info config_options_info[] = { "goto-url-home action. Set to \"\" if the environment " "variable WWW_HOME should be used as homepage URI instead.")), + INIT_OPT_BOOL("ui.sessions", N_("Keep session active"), + "keep_session_active", 0, 0, + N_("Keep the session active even if the last terminal " + "exits.")), + #ifdef HAVE_STRFTIME INIT_OPT_STRING("ui", N_("Date format"), "date_format", 0, "%b %e %H:%M", diff --git a/src/main/interlink.c b/src/main/interlink.c index 35a71986..f5ea559f 100644 --- a/src/main/interlink.c +++ b/src/main/interlink.c @@ -42,8 +42,10 @@ #include "elinks.h" #include "config/home.h" +#include "config/options.h" #include "intl/gettext/libintl.h" #include "main/interlink.h" +#include "main/main.h" #include "main/select.h" #include "osdep/osdep.h" #include "session/session.h" @@ -520,21 +522,26 @@ init_interlink(void) if (fd != -1 || remote_session_flags) return fd; - pid = fork(); + parse_options_again(); - if (pid == -1) return -1; - if (pid > 0) { - int i; + if (get_opt_bool("ui.sessions.fork_on_start", NULL)) { + pid = fork(); - for (i = 1; i <= (MAX_BIND_TRIES+2); ++i) { - fd = connect_to_af_unix(); + if (pid == -1) return -1; - if (fd != -1) return fd; - elinks_usleep(BIND_TRIES_DELAY * i); + if (pid > 0) { + int i; + + for (i = 1; i <= (MAX_BIND_TRIES+2); ++i) { + fd = connect_to_af_unix(); + + if (fd != -1) return fd; + elinks_usleep(BIND_TRIES_DELAY * i); + } + return -1; } - return -1; + close_terminal_pipes(); } - close_terminal_pipes(); bind_to_af_unix(); return -1; } diff --git a/src/main/main.c b/src/main/main.c index 71ac42ea..65a297a8 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -104,6 +104,24 @@ check_cwd(void) mem_free_if(cwd); } +void +parse_options_again(void) +{ + if (!init_b) { + load_config(); + update_options_visibility(); + /* Parse commandline options again, in order to override any + * config file options. */ + parse_options(ac - 1, av + 1, NULL); + /* ... and re-check stdio, in order to override any command + * line options! >;) */ + if (!remote_session_flags) { + check_stdio(NULL); + } + init_b = 1; + } +} + static void init(void) { @@ -171,18 +189,7 @@ init(void) || get_cmd_opt_bool("source") || (fd = init_interlink()) == -1) { - load_config(); - update_options_visibility(); - /* Parse commandline options again, in order to override any - * config file options. */ - parse_options(ac - 1, av + 1, NULL); - /* ... and re-check stdio, in order to override any command - * line options! >;) */ - if (!remote_session_flags) { - check_stdio(NULL); - } - - init_b = 1; + parse_options_again(); init_modules(builtin_modules); } @@ -235,7 +242,8 @@ init(void) handle_trm(get_input_handle(), get_output_handle(), fd, fd, get_ctl_handle(), info.source, info.length, remote_session_flags); - } else if (get_cmd_opt_bool("no-connect")) { + } else if (get_cmd_opt_bool("no-connect") + || !get_opt_bool("ui.sessions.fork_on_start", NULL)) { /* Setup a master terminal */ term = attach_terminal(get_input_handle(), get_output_handle(), get_ctl_handle(), info.source, info.length); diff --git a/src/main/main.h b/src/main/main.h index a4aa4fb6..cddbb53f 100644 --- a/src/main/main.h +++ b/src/main/main.h @@ -21,5 +21,6 @@ struct program { extern struct program program; void shrink_memory(int); +void parse_options_again(void); #endif