aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/autocmd.txt6
-rw-r--r--runtime/doc/vim_diff.txt1
-rw-r--r--src/nvim/auevents.lua2
-rw-r--r--src/nvim/fileio.c1
-rw-r--r--src/nvim/os/signal.c23
-rw-r--r--test/functional/autocmd/signal_spec.lua38
6 files changed, 70 insertions, 1 deletions
diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt
index d7b74f99c2..6423939b83 100644
--- a/runtime/doc/autocmd.txt
+++ b/runtime/doc/autocmd.txt
@@ -353,6 +353,8 @@ Name triggered by ~
|CompleteDone| after Insert mode completion is done
|User| to be used in combination with ":doautocmd"
+|Signal| after the nvim process received a signal
+
The alphabetical list of autocommand events: *autocmd-events-abc*
@@ -914,6 +916,10 @@ ShellCmdPost After executing a shell command with |:!cmd|,
any changed files.
For non-blocking shell commands, see
|job-control|.
+ *Signal*
+Signal After the nvim process received a signal.
+ The pattern is matched against the name of the
+ received signal. Only "SIGUSR1" is supported.
*ShellFilterPost*
ShellFilterPost After executing a shell command with
":{range}!cmd", ":w !cmd" or ":r !cmd".
diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt
index 36630d14ac..33260ab53b 100644
--- a/runtime/doc/vim_diff.txt
+++ b/runtime/doc/vim_diff.txt
@@ -142,6 +142,7 @@ Commands:
Events:
|DirChanged|
+ |Signal|
|TabNewEntered|
|TermClose|
|TermOpen|
diff --git a/src/nvim/auevents.lua b/src/nvim/auevents.lua
index 3cffd66dee..cc0ed0f587 100644
--- a/src/nvim/auevents.lua
+++ b/src/nvim/auevents.lua
@@ -74,6 +74,7 @@ return {
'SessionLoadPost', -- after loading a session file
'ShellCmdPost', -- after ":!cmd"
'ShellFilterPost', -- after ":1,2!cmd", ":w !cmd", ":r !cmd".
+ 'Signal', -- after nvim process received a signal
'SourceCmd', -- sourcing a Vim script using command
'SourcePre', -- before sourcing a Vim script
'SpellFileMissing', -- spell file missing
@@ -115,6 +116,7 @@ return {
-- syntax file
nvim_specific = {
DirChanged=true,
+ Signal=true,
TabClosed=true,
TabNew=true,
TabNewEntered=true,
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index ba154ea36a..6356290b9c 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -6917,6 +6917,7 @@ static bool apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io,
|| event == EVENT_REMOTEREPLY
|| event == EVENT_SPELLFILEMISSING
|| event == EVENT_SYNTAX
+ || event == EVENT_SIGNAL
|| event == EVENT_TABCLOSED) {
fname = vim_strsave(fname);
} else {
diff --git a/src/nvim/os/signal.c b/src/nvim/os/signal.c
index fc7f9cefd1..20f68233e7 100644
--- a/src/nvim/os/signal.c
+++ b/src/nvim/os/signal.c
@@ -15,6 +15,7 @@
#include "nvim/globals.h"
#include "nvim/memline.h"
#include "nvim/eval.h"
+#include "nvim/fileio.h"
#include "nvim/main.h"
#include "nvim/memory.h"
#include "nvim/misc1.h"
@@ -22,7 +23,7 @@
#include "nvim/os/signal.h"
#include "nvim/event/loop.h"
-static SignalWatcher spipe, shup, squit, sterm;
+static SignalWatcher spipe, shup, squit, sterm, susr1;
#ifdef SIGPWR
static SignalWatcher spwr;
#endif
@@ -61,6 +62,10 @@ void signal_init(void)
signal_watcher_init(&main_loop, &spwr, NULL);
signal_watcher_start(&spwr, on_signal, SIGPWR);
#endif
+#ifdef SIGUSR1
+ signal_watcher_init(&main_loop, &susr1, NULL);
+ signal_watcher_start(&susr1, on_signal, SIGUSR1);
+#endif
}
void signal_teardown(void)
@@ -73,6 +78,9 @@ void signal_teardown(void)
#ifdef SIGPWR
signal_watcher_close(&spwr, NULL);
#endif
+#ifdef SIGUSR1
+ signal_watcher_close(&susr1, NULL);
+#endif
}
void signal_stop(void)
@@ -84,6 +92,9 @@ void signal_stop(void)
#ifdef SIGPWR
signal_watcher_stop(&spwr);
#endif
+#ifdef SIGUSR1
+ signal_watcher_stop(&susr1);
+#endif
}
void signal_reject_deadly(void)
@@ -115,6 +126,10 @@ static char * signal_name(int signum)
#endif
case SIGHUP:
return "SIGHUP";
+#ifdef SIGUSR1
+ case SIGUSR1:
+ return "SIGUSR1";
+#endif
default:
return "Unknown";
}
@@ -162,6 +177,12 @@ static void on_signal(SignalWatcher *handle, int signum, void *data)
deadly_signal(signum);
}
break;
+#ifdef SIGUSR1
+ case SIGUSR1:
+ apply_autocmds(EVENT_SIGNAL, (char_u *)"SIGUSR1", curbuf->b_fname, true,
+ curbuf);
+ break;
+#endif
default:
ELOG("invalid signal: %d", signum);
break;
diff --git a/test/functional/autocmd/signal_spec.lua b/test/functional/autocmd/signal_spec.lua
new file mode 100644
index 0000000000..719adeaf1b
--- /dev/null
+++ b/test/functional/autocmd/signal_spec.lua
@@ -0,0 +1,38 @@
+local helpers = require('test.functional.helpers')(after_each)
+
+local clear = helpers.clear
+local command = helpers.command
+local eq = helpers.eq
+local funcs = helpers.funcs
+local next_msg = helpers.next_msg
+
+if helpers.pending_win32(pending) then
+ -- Only applies to POSIX systems.
+ return
+end
+
+local function posix_kill(signame, pid)
+ os.execute('kill -s '..signame..' -- '..pid..' >/dev/null')
+end
+
+describe('autocmd Signal', function()
+ before_each(clear)
+
+ it('matches *', function()
+ command('autocmd Signal * call rpcnotify(1, "foo")')
+ posix_kill('USR1', funcs.getpid())
+ eq({'notification', 'foo', {}}, next_msg())
+ end)
+
+ it('matches SIGUSR1', function()
+ command('autocmd Signal SIGUSR1 call rpcnotify(1, "foo")')
+ posix_kill('USR1', funcs.getpid())
+ eq({'notification', 'foo', {}}, next_msg())
+ end)
+
+ it('does not match unknown patterns', function()
+ command('autocmd Signal SIGUSR2 call rpcnotify(1, "foo")')
+ posix_kill('USR1', funcs.getpid())
+ eq(nil, next_msg(500))
+ end)
+end)