Allow reloading config by sending the SIGUSR1 signal

This commit is contained in:
Kovid Goyal 2021-06-07 20:51:45 +05:30
parent ec1303a232
commit df05339d2a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 29 additions and 12 deletions

View File

@ -11,8 +11,8 @@ possibilities.
You can open the config file within kitty by pressing :sc:`edit_config_file`. You can open the config file within kitty by pressing :sc:`edit_config_file`.
You can reload the config file within kitty by pressing You can reload the config file within kitty by pressing
:sc:`reload_config_file`. You can also display the current configuration by :sc:`reload_config_file` or sending kitty the ``SIGUSR1`` signal. You can also
pressing the :sc:`debug_config` key. display the current configuration by pressing the :sc:`debug_config` key.
.. _confloc: .. _confloc:

View File

@ -83,7 +83,7 @@ static unsigned long remove_notify[MAX_CHILDREN] = {0};
static size_t add_queue_count = 0, remove_queue_count = 0; static size_t add_queue_count = 0, remove_queue_count = 0;
static struct pollfd fds[MAX_CHILDREN + EXTRA_FDS] = {{0}}; static struct pollfd fds[MAX_CHILDREN + EXTRA_FDS] = {{0}};
static pthread_mutex_t children_lock, talk_lock; static pthread_mutex_t children_lock, talk_lock;
static bool kill_signal_received = false; static bool kill_signal_received = false, reload_config_signal_received = false;
static ChildMonitor *the_monitor = NULL; static ChildMonitor *the_monitor = NULL;
typedef struct { typedef struct {
@ -333,7 +333,7 @@ static bool
parse_input(ChildMonitor *self) { parse_input(ChildMonitor *self) {
// Parse all available input that was read in the I/O thread. // Parse all available input that was read in the I/O thread.
size_t count = 0, remove_count = 0; size_t count = 0, remove_count = 0;
bool input_read = false; bool input_read = false, reload_config_called = false;
monotonic_t now = monotonic(); monotonic_t now = monotonic();
children_mutex(lock); children_mutex(lock);
while (remove_queue_count) { while (remove_queue_count) {
@ -343,11 +343,17 @@ parse_input(ChildMonitor *self) {
FREE_CHILD(remove_queue[remove_queue_count]); FREE_CHILD(remove_queue[remove_queue_count]);
} }
if (UNLIKELY(kill_signal_received)) { if (UNLIKELY(kill_signal_received || reload_config_signal_received)) {
global_state.quit_request = IMPERATIVE_CLOSE_REQUESTED; if (kill_signal_received) {
global_state.has_pending_closes = true; global_state.quit_request = IMPERATIVE_CLOSE_REQUESTED;
request_tick_callback(); global_state.has_pending_closes = true;
kill_signal_received = false; request_tick_callback();
kill_signal_received = false;
}
else if (reload_config_signal_received) {
reload_config_signal_received = false;
reload_config_called = true;
}
} else { } else {
count = self->count; count = self->count;
for (size_t i = 0; i < count; i++) { for (size_t i = 0; i < count; i++) {
@ -402,6 +408,9 @@ parse_input(ChildMonitor *self) {
} }
DECREF_CHILD(scratch[i]); DECREF_CHILD(scratch[i]);
} }
if (reload_config_called) {
call_boss(load_config_file, "");
}
return input_read; return input_read;
} }
@ -1145,7 +1154,7 @@ read_bytes(int fd, Screen *screen) {
} }
typedef struct { bool kill_signal, child_died; } SignalSet; typedef struct { bool kill_signal, child_died, reload_config; } SignalSet;
static void static void
handle_signal(int signum, void *data) { handle_signal(int signum, void *data) {
@ -1158,6 +1167,9 @@ handle_signal(int signum, void *data) {
case SIGCHLD: case SIGCHLD:
ss->child_died = true; ss->child_died = true;
break; break;
case SIGUSR1:
ss->reload_config = true;
break;
default: default:
break; break;
} }
@ -1272,7 +1284,12 @@ io_loop(void *data) {
SignalSet ss = {0}; SignalSet ss = {0};
data_received = true; data_received = true;
read_signals(fds[1].fd, handle_signal, &ss); read_signals(fds[1].fd, handle_signal, &ss);
if (ss.kill_signal) { children_mutex(lock); kill_signal_received = true; children_mutex(unlock); } if (ss.kill_signal || ss.reload_config) {
children_mutex(lock);
if (ss.kill_signal) kill_signal_received = true;
if (ss.reload_config) reload_config_signal_received = true;
children_mutex(unlock);
}
if (ss.child_died) reap_children(self, OPT(close_on_child_death)); if (ss.child_died) reap_children(self, OPT(close_on_child_death));
} }
for (i = 0; i < self->count; i++) { for (i = 0; i < self->count; i++) {

View File

@ -45,7 +45,7 @@ handle_signal(int sig_num) {
#define SIGNAL_SET \ #define SIGNAL_SET \
sigset_t signals = {0}; \ sigset_t signals = {0}; \
sigemptyset(&signals); \ sigemptyset(&signals); \
sigaddset(&signals, SIGINT); sigaddset(&signals, SIGTERM); sigaddset(&signals, SIGCHLD); \ sigaddset(&signals, SIGINT); sigaddset(&signals, SIGTERM); sigaddset(&signals, SIGCHLD); sigaddset(&signals, SIGUSR1); \
void void
free_loop_data(LoopData *ld) { free_loop_data(LoopData *ld) {