summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpgen <p.gen.progs@gmail.com>2021-08-28 01:36:46 +0200
committerpgen <p.gen.progs@gmail.com>2021-08-28 01:38:12 +0200
commit0a804a7ba9c20b505e97528c1f2b1db547ab825a (patch)
treeb6e627befe6003ce640a0a0e88c97a55c061a23f
parentefc51dfabb437a81f16017b12d9ea9d58ac4a552 (diff)
Add a global timeout which defaults to 15min
A new option can be used to modify this value: -f|-forgotten_timeout|-global_timeout
-rw-r--r--smenu.110
-rw-r--r--smenu.c160
-rw-r--r--smenu.h10
-rw-r--r--usage.c2
4 files changed, 131 insertions, 51 deletions
diff --git a/smenu.1 b/smenu.1
index b816084..c2ecd6e 100644
--- a/smenu.1
+++ b/smenu.1
@@ -67,6 +67,7 @@ and outputs the selection to stdout.
[\fB-v\fP|\fB-vb\fP|\fB-visual_bell\fP]
[\fB-Q\fP|\fB-ignore_quotes\fP]
[\fB-lim\fP|\fB-limits\fP \fIlimit:value\fP...]
+ [\fB-f\fP|\fB-forgotten_timeout\fP|\fB-global_timeout\fP \fItimeout\fP]
selectors ::= \fIcol1\fP[-\fIcol2\fP],...|\fIrow1\fP[-\fIrow2\fP],...|\
@@ -1627,6 +1628,15 @@ to set the maximum number of words allowed.
to set the maximum number of columns allowed.
.RE
+.IP "[\fB-f\fP|\fB-forgotten_timeout\fP|\fB-global_timeout\fP \fItimeout\fP]"
+(Allowed in all contexts.)
+
+This option defines a global timeout in seconds.
+The program will end without error after this period of inactivity.
+
+This timer is rearmed to its initial value on every keystroke.
+
+Its default value is 900 seconds (15 minutes).
.SH NOTES
If tabulators (\fI\\t\fP) are embedded in the input, there is no way
to replace them with the original number of spaces.
diff --git a/smenu.c b/smenu.c
index d55039c..0eba974 100644
--- a/smenu.c
+++ b/smenu.c
@@ -114,15 +114,16 @@ long alt_matches_count;
/* Variables used in signal handlers. */
/* """""""""""""""""""""""""""""""""" */
-volatile sig_atomic_t got_winch = 0;
-volatile sig_atomic_t got_winch_alrm = 0;
-volatile sig_atomic_t got_help_alrm = 0;
-volatile sig_atomic_t got_daccess_alrm = 0;
-volatile sig_atomic_t got_search_alrm = 0;
-volatile sig_atomic_t got_timeout_tick = 0;
-volatile sig_atomic_t got_sigsegv = 0;
-volatile sig_atomic_t got_sigterm = 0;
-volatile sig_atomic_t got_sighup = 0;
+volatile sig_atomic_t got_winch = 0;
+volatile sig_atomic_t got_winch_alrm = 0;
+volatile sig_atomic_t got_forgotten_alrm = 0;
+volatile sig_atomic_t got_help_alrm = 0;
+volatile sig_atomic_t got_daccess_alrm = 0;
+volatile sig_atomic_t got_search_alrm = 0;
+volatile sig_atomic_t got_timeout_tick = 0;
+volatile sig_atomic_t got_sigsegv = 0;
+volatile sig_atomic_t got_sigterm = 0;
+volatile sig_atomic_t got_sighup = 0;
/* Variables used when a timeout is set (option -x). */
/* """"""""""""""""""""""""""""""""""""""""""""""""" */
@@ -3916,6 +3917,12 @@ sig_handler(int s)
if (timeout.initial_value > 0)
got_timeout_tick = 1;
+ if (forgotten_timer > 0)
+ forgotten_timer--;
+
+ if (forgotten_timer == 0)
+ got_forgotten_alrm = 1;
+
if (help_timer > 0)
help_timer--;
@@ -4937,6 +4944,7 @@ init_main_ds(attrib_t * init_attr, win_t * win, limit_t * limits,
/* Default timers in 1/10 s. */
/* """"""""""""""""""""""""" */
timers->search = 100 * FREQ / 10;
+ timers->forgotten = 9000 * FREQ / 10;
timers->help = 300 * FREQ / 10;
timers->winch = 20 * FREQ / 10;
timers->direct_access = 6 * FREQ / 10;
@@ -6082,6 +6090,39 @@ ignore_quotes_action(char * ctx_name, char * opt_name, char * param,
misc->ignore_quotes = 1;
}
+void
+forgotten_action(char * ctx_name, char * opt_name, char * param, int nb_values,
+ char ** values, int nb_opt_data, void ** opt_data,
+ int nb_ctx_data, void ** ctx_data)
+{
+ ticker_t * timers = opt_data[0];
+
+ long val;
+ char * endptr;
+ char * p;
+ size_t l = strlen(values[0]);
+
+ /* Add a 0 at the end of the parameter to multiply it by 10 */
+ /* as the timer values must be in tenths of seconds. */
+ /* """""""""""""""""""""""""""""""""""""""""""""""""""""""" */
+ p = xmalloc(l + 2);
+ p = strcpy(p, values[0]);
+ p[l] = '0';
+
+ val = strtol(p, &endptr, 0);
+ if (errno == ERANGE || (val == 0 && errno != 0) || endptr == p
+ || *endptr != '\0')
+ {
+ fprintf(stderr, "%s: Invalid timeout delay\n", values[0]);
+ free(p);
+ ctxopt_ctx_disp_usage(ctx_name, exit_after);
+ }
+ else
+ timers->forgotten = (int)val;
+
+ free(p);
+}
+
/* =================================================================== */
/* Cancels a search. Called when ESC is hit or a new search session is */
/* initiated and the incremental_search option is not used. */
@@ -6647,44 +6688,46 @@ main(int argc, char * argv[])
"allow_abbreviations=No "
"display_usage_on_error=Yes ");
- common_options = "[*help] "
- "[*usage] "
- "[include_re... #regex] "
- "[exclude_re... #regex] "
- "[title #message] "
- "[int [#string]] "
- "[attributes #prefix:attr...] "
- "[special_level_1 #...<3] "
- "[special_level_2 #...<3] "
- "[special_level_3 #...<3] "
- "[special_level_4 #...<3] "
- "[special_level_5 #...<3] "
- "[special_level_6 #...<3] "
- "[special_level_7 #...<3] "
- "[special_level_8 #...<3] "
- "[special_level_9 #...<3] "
- "[zapped_glyphs #bytes] "
- "[lines [#height]] "
- "[blank_nonprintable] "
- "[*invalid_character #invalid_char_subst] "
- "[center_mode] "
- "[clean] "
- "[keep_spaces] "
- "[word_separators #bytes] "
- "[no_scroll_bar] "
- "[early_subst_all... #/regex/repl/opts] "
- "[post_subst_all... #/regex/repl/opts] "
- "[post_subst_included... #/regex/repl/opts] "
- "[post_subst_excluded... #/regex/repl/opts] "
- "[search_method #prefix|substring|fuzzy] "
- "[start_pattern #pattern] "
- "[timeout #...] "
- "[hidden_timeout #...] "
- "[validate_in_search_mode] "
- "[visual_bell] "
- "[ignore_quotes] "
- "[incremental_search] "
- "[limits #limit:value...] "; /* don't remove this space! */
+ common_options =
+ "[*help] "
+ "[*usage] "
+ "[include_re... #regex] "
+ "[exclude_re... #regex] "
+ "[title #message] "
+ "[int [#string]] "
+ "[attributes #prefix:attr...] "
+ "[special_level_1 #...<3] "
+ "[special_level_2 #...<3] "
+ "[special_level_3 #...<3] "
+ "[special_level_4 #...<3] "
+ "[special_level_5 #...<3] "
+ "[special_level_6 #...<3] "
+ "[special_level_7 #...<3] "
+ "[special_level_8 #...<3] "
+ "[special_level_9 #...<3] "
+ "[zapped_glyphs #bytes] "
+ "[lines [#height]] "
+ "[blank_nonprintable] "
+ "[*invalid_character #invalid_char_subst] "
+ "[center_mode] "
+ "[clean] "
+ "[keep_spaces] "
+ "[word_separators #bytes] "
+ "[no_scroll_bar] "
+ "[early_subst_all... #/regex/repl/opts] "
+ "[post_subst_all... #/regex/repl/opts] "
+ "[post_subst_included... #/regex/repl/opts] "
+ "[post_subst_excluded... #/regex/repl/opts] "
+ "[search_method #prefix|substring|fuzzy] "
+ "[start_pattern #pattern] "
+ "[timeout #...] "
+ "[hidden_timeout #...] "
+ "[validate_in_search_mode] "
+ "[visual_bell] "
+ "[ignore_quotes] "
+ "[incremental_search] "
+ "[limits #limit:value...] "
+ "[forgotten_timeout #timeout] "; /* don't remove this space! */
main_spec_options = "[*version] "
"[*long_help] "
@@ -6840,6 +6883,8 @@ main(int argc, char * argv[])
ctxopt_add_opt_settings(parameters, "incremental_search",
"-is -incremental_search");
ctxopt_add_opt_settings(parameters, "limits", "-lim -limits");
+ ctxopt_add_opt_settings(parameters, "forgotten_timeout",
+ "-f -forgotten_timeout -global_timeout");
/* ctxopt options incompatibilities. */
/* """"""""""""""""""""""""""""""""" */
@@ -6989,6 +7034,8 @@ main(int argc, char * argv[])
ctxopt_add_opt_settings(actions, "ignore_quotes", ignore_quotes_action, &misc,
(char *)0);
ctxopt_add_opt_settings(actions, "limits", limits_action, &limits, (char *)0);
+ ctxopt_add_opt_settings(actions, "forgotten_timeout", forgotten_action,
+ &timers, (char *)0);
/* ctxopt constraints. */
/* """"""""""""""""""" */
@@ -7424,6 +7471,10 @@ main(int argc, char * argv[])
}
}
+ /* Initialize and arm the global (forgotten) timer. */
+ /* """""""""""""""""""""""""""""""""""""""""""""""" */
+ forgotten_timer = timers.forgotten;
+
/* Initialize the timeout message when the x/X option is set. */
/* """""""""""""""""""""""""""""""""""""""""""""""""""""""""" */
if (!quiet_timeout && timeout.initial_value > 0)
@@ -9464,6 +9515,17 @@ main(int argc, char * argv[])
exit(128 + SIGHUP);
}
+ /* If this alarm is triggered, then gracefully exit. */
+ /* """"""""""""""""""""""""""""""""""""""""""""""""" */
+ if (got_forgotten_alrm)
+ {
+ tputs(TPARM1(carriage_return), 1, outch);
+ tputs(TPARM1(cursor_normal), 1, outch);
+ restore_term(fileno(stdin));
+
+ exit(0);
+ }
+
/* If this alarm is triggered, then redisplay the window */
/* to remove the help message and disable this timer. */
/* """"""""""""""""""""""""""""""""""""""""""""""""""""" */
@@ -9711,6 +9773,10 @@ main(int argc, char * argv[])
if (sc && winch_timer < 0) /* Do not allow input when a window *
| refresh is scheduled. */
{
+ /* Rearm the forgotten timer. */
+ /* """""""""""""""""""""""""" */
+ forgotten_timer = timers.forgotten; /* default 900 s (15 min). */
+
if (timeout.initial_value && buffer[0] != 0x0d && buffer[0] != 'q'
&& buffer[0] != 'Q' && buffer[0] != 3)
{
diff --git a/smenu.h b/smenu.h
index 55317c1..dc1f964 100644
--- a/smenu.h
+++ b/smenu.h
@@ -181,6 +181,7 @@ struct limit_s
struct ticker_s
{
int search;
+ int forgotten;
int help;
int winch;
int direct_access;
@@ -204,10 +205,11 @@ struct termios old_in_attrs;
/* """"""""""""""""""""" */
struct itimerval periodic_itv; /* refresh rate for the timeout counter. */
-int help_timer = -1;
-int winch_timer = -1;
-int daccess_timer = -1;
-int search_timer = -1;
+int forgotten_timer = -1;
+int help_timer = -1;
+int winch_timer = -1;
+int daccess_timer = -1;
+int search_timer = -1;
/* Structure containing the attributes components. */
/* """"""""""""""""""""""""""""""""""""""""""""""" */
diff --git a/usage.c b/usage.c
index f87d1ba..955d9fb 100644
--- a/usage.c
+++ b/usage.c
@@ -94,6 +94,8 @@ common_help(void)
printf(" treats single and double quotes as normal characters.\n");
printf("-lim|-limits\n");
printf(" overload the words number/max. word length/max columns limits.\n");
+ printf("f|-forgotten_timeout|-global_timeout");
+ printf(" defines a global inactivity timeout, defaults to 15 min.\n");
}
void