diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-06-10 20:56:58 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-06-10 20:56:58 +0200 |
commit | be5ee8686a50acf07b823bd293f9c765e533d213 (patch) | |
tree | fc5056db66c81eefa83a30afae305b9b027677d8 /src | |
parent | 6ba24d87630b1ec2b8c7ff71550c9e41d143800e (diff) |
patch 8.2.0952: no simple way to interrupt Vimv8.2.0952
Problem: No simple way to interrupt Vim.
Solution: Add the SigUSR1 autocommand, triggered by SIGUSR1. (Jacob Hayes,
closes #1718)
Diffstat (limited to 'src')
-rw-r--r-- | src/autocmd.c | 1 | ||||
-rw-r--r-- | src/getchar.c | 7 | ||||
-rw-r--r-- | src/globals.h | 11 | ||||
-rw-r--r-- | src/os_unix.c | 27 | ||||
-rw-r--r-- | src/testdir/test_autocmd.vim | 13 | ||||
-rw-r--r-- | src/version.c | 2 | ||||
-rw-r--r-- | src/vim.h | 1 |
7 files changed, 56 insertions, 6 deletions
diff --git a/src/autocmd.c b/src/autocmd.c index 937e74187f..8e0754b690 100644 --- a/src/autocmd.c +++ b/src/autocmd.c @@ -161,6 +161,7 @@ static struct event_name {"SessionLoadPost", EVENT_SESSIONLOADPOST}, {"ShellCmdPost", EVENT_SHELLCMDPOST}, {"ShellFilterPost", EVENT_SHELLFILTERPOST}, + {"SigUSR1", EVENT_SIGUSR1}, {"SourceCmd", EVENT_SOURCECMD}, {"SourcePre", EVENT_SOURCEPRE}, {"SourcePost", EVENT_SOURCEPOST}, diff --git a/src/getchar.c b/src/getchar.c index fcee7dda72..2beffa5784 100644 --- a/src/getchar.c +++ b/src/getchar.c @@ -2204,6 +2204,13 @@ parse_queued_messages(void) if (has_sound_callback_in_queue()) invoke_sound_callback(); # endif +#ifdef SIGUSR1 + if (got_sigusr1) + { + apply_autocmds(EVENT_SIGUSR1, NULL, NULL, FALSE, curbuf); + got_sigusr1 = FALSE; + } +#endif break; } diff --git a/src/globals.h b/src/globals.h index 27a8d68146..b8fd231dfa 100644 --- a/src/globals.h +++ b/src/globals.h @@ -1171,9 +1171,14 @@ EXTERN int curscript INIT(= 0); // index in scriptin[] EXTERN FILE *scriptout INIT(= NULL); // stream to write script to EXTERN int read_cmd_fd INIT(= 0); // fd to read commands from -// volatile because it is used in signal handler catch_sigint(). -EXTERN volatile sig_atomic_t got_int INIT(= FALSE); // set to TRUE when interrupt - // signal occurred +// Set to TRUE when an interrupt signal occurred. +// Volatile because it is used in signal handler catch_sigint(). +EXTERN volatile sig_atomic_t got_int INIT(= FALSE); + +// Set to TRUE when SIGUSR1 signal was detected. +// Volatile because it is used in signal handler catch_sigint(). +EXTERN volatile sig_atomic_t got_sigusr1 INIT(= FALSE); + #ifdef USE_TERM_CONSOLE EXTERN int term_console INIT(= FALSE); // set to TRUE when console used #endif diff --git a/src/os_unix.c b/src/os_unix.c index c6ba2499bd..095e3a78e2 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -164,6 +164,9 @@ static RETSIGTYPE sig_winch SIGPROTOARG; #if defined(SIGINT) static RETSIGTYPE catch_sigint SIGPROTOARG; #endif +#if defined(SIGUSR1) +static RETSIGTYPE catch_sigusr1 SIGPROTOARG; +#endif #if defined(SIGPWR) static RETSIGTYPE catch_sigpwr SIGPROTOARG; #endif @@ -297,7 +300,7 @@ static struct signalinfo {SIGXFSZ, "XFSZ", TRUE}, #endif #ifdef SIGUSR1 - {SIGUSR1, "USR1", TRUE}, + {SIGUSR1, "USR1", FALSE}, #endif #if defined(SIGUSR2) && !defined(FEAT_SYSMOUSE) // Used for sysmouse handling @@ -837,6 +840,17 @@ catch_sigint SIGDEFARG(sigarg) } #endif +#if defined(SIGUSR1) + static RETSIGTYPE +catch_sigusr1 SIGDEFARG(sigarg) +{ + // this is not required on all systems, but it doesn't hurt anybody + signal(SIGUSR1, (RETSIGTYPE (*)())catch_sigusr1); + got_sigusr1 = TRUE; + SIGRETURN; +} +#endif + #if defined(SIGPWR) static RETSIGTYPE catch_sigpwr SIGDEFARG(sigarg) @@ -1323,10 +1337,10 @@ set_signals(void) #if defined(SIGCONT) signal(SIGCONT, sigcont_handler); #endif +#ifdef SIGPIPE /* * We want to ignore breaking of PIPEs. */ -#ifdef SIGPIPE signal(SIGPIPE, SIG_IGN); #endif @@ -1334,6 +1348,13 @@ set_signals(void) catch_int_signal(); #endif +#ifdef SIGUSR1 + /* + * Call user's handler on SIGUSR1 + */ + signal(SIGUSR1, (RETSIGTYPE (*)())catch_sigusr1); +#endif + /* * Ignore alarm signals (Perl's alarm() generates it). */ @@ -1341,11 +1362,11 @@ set_signals(void) signal(SIGALRM, SIG_IGN); #endif +#ifdef SIGPWR /* * Catch SIGPWR (power failure?) to preserve the swap files, so that no * work will be lost. */ -#ifdef SIGPWR signal(SIGPWR, (RETSIGTYPE (*)())catch_sigpwr); #endif diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim index b7a523e39a..9ac7070057 100644 --- a/src/testdir/test_autocmd.vim +++ b/src/testdir/test_autocmd.vim @@ -2509,4 +2509,17 @@ func Test_autocmd_deep_nesting() autocmd! BufEnter Xfile endfunc +" Tests for SigUSR1 autocmd event, which is only available on posix systems. +func Test_autocmd_sigusr1() + CheckUnix + + let g:sigusr1_passed = 0 + au SigUSR1 * let g:sigusr1_passed = 1 + call system('/bin/kill -s usr1 ' . getpid()) + call WaitForAssert({-> assert_true(g:sigusr1_passed)}) + + au! SigUSR1 + unlet g:sigusr1_passed +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/version.c b/src/version.c index 7b292acde0..0ed018c849 100644 --- a/src/version.c +++ b/src/version.c @@ -755,6 +755,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 952, +/**/ 951, /**/ 950, @@ -1316,6 +1316,7 @@ enum auto_event EVENT_SESSIONLOADPOST, // after loading a session file EVENT_SHELLCMDPOST, // after ":!cmd" EVENT_SHELLFILTERPOST, // after ":1,2!cmd", ":w !cmd", ":r !cmd". + EVENT_SIGUSR1, // after the SIGUSR1 signal EVENT_SOURCECMD, // sourcing a Vim script using command EVENT_SOURCEPRE, // before sourcing a Vim script EVENT_SOURCEPOST, // after sourcing a Vim script |