feat(events): support SIGWINCH for Signal event #18029

closes #15411
This commit is contained in:
Loong Wang 2022-04-11 06:56:08 +08:00 committed by GitHub
parent 8bdcd832ae
commit b2cb05b53e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 2 deletions

View File

@ -870,7 +870,7 @@ ShellCmdPost After executing a shell command with |:!cmd|,
*Signal*
Signal After Nvim receives a signal. The pattern is
matched against the signal name. Only
"SIGUSR1" is supported. Example: >
"SIGUSR1" and "SIGWINCH" are supported. Example: >
autocmd Signal SIGUSR1 call some#func()
< *ShellFilterPost*
ShellFilterPost After executing a shell command with

View File

@ -21,7 +21,7 @@
#include "nvim/os/signal.h"
#include "nvim/vim.h"
static SignalWatcher spipe, shup, squit, sterm, susr1;
static SignalWatcher spipe, shup, squit, sterm, susr1, swinch;
#ifdef SIGPWR
static SignalWatcher spwr;
#endif
@ -53,6 +53,9 @@ void signal_init(void)
#endif
#ifdef SIGUSR1
signal_watcher_init(&main_loop, &susr1, NULL);
#endif
#ifdef SIGWINCH
signal_watcher_init(&main_loop, &swinch, NULL);
#endif
signal_start();
}
@ -70,6 +73,9 @@ void signal_teardown(void)
#ifdef SIGUSR1
signal_watcher_close(&susr1, NULL);
#endif
#ifdef SIGWINCH
signal_watcher_close(&swinch, NULL);
#endif
}
void signal_start(void)
@ -88,6 +94,9 @@ void signal_start(void)
#ifdef SIGUSR1
signal_watcher_start(&susr1, on_signal, SIGUSR1);
#endif
#ifdef SIGWINCH
signal_watcher_start(&swinch, on_signal, SIGWINCH);
#endif
}
void signal_stop(void)
@ -106,6 +115,9 @@ void signal_stop(void)
#ifdef SIGUSR1
signal_watcher_stop(&susr1);
#endif
#ifdef SIGWINCH
signal_watcher_stop(&swinch);
#endif
}
void signal_reject_deadly(void)
@ -140,6 +152,10 @@ static char *signal_name(int signum)
#ifdef SIGUSR1
case SIGUSR1:
return "SIGUSR1";
#endif
#ifdef SIGWINCH
case SIGWINCH:
return "SIGWINCH";
#endif
default:
return "Unknown";
@ -197,6 +213,12 @@ static void on_signal(SignalWatcher *handle, int signum, void *data)
apply_autocmds(EVENT_SIGNAL, (char_u *)"SIGUSR1", curbuf->b_fname, true,
curbuf);
break;
#endif
#ifdef SIGWINCH
case SIGWINCH:
apply_autocmds(EVENT_SIGNAL, (char_u *)"SIGWINCH", curbuf->b_fname, true,
curbuf);
break;
#endif
default:
ELOG("invalid signal: %d", signum);

View File

@ -30,6 +30,12 @@ describe('autocmd Signal', function()
eq({'notification', 'foo', {}}, next_msg())
end)
it('matches SIGWINCH', function()
command('autocmd Signal SIGWINCH call rpcnotify(1, "foo")')
posix_kill('WINCH', 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())