Allow reloading config on SIGHUP

Before this commit qutebrowser would just exit when receiving a SIGHUP.
Now it will reload the config using the bare config_source function, just like
the :config-source command does.
Closes #8108.
This commit is contained in:
tarneo 2024-02-21 21:15:10 +01:00
parent b92f053350
commit 566c07c789
No known key found for this signature in database
GPG Key ID: BA924E53D0EB3FCC
1 changed files with 11 additions and 0 deletions

View File

@ -335,6 +335,8 @@ class SignalHandler(QObject):
signal.SIGINT, self.interrupt)
self._orig_handlers[signal.SIGTERM] = signal.signal(
signal.SIGTERM, self.interrupt)
self._orig_handlers[signal.SIGHUP] = signal.signal(
signal.SIGHUP, self.reload_config)
if utils.is_posix and hasattr(signal, 'set_wakeup_fd'):
# pylint: disable=import-error,no-member,useless-suppression
@ -430,6 +432,15 @@ class SignalHandler(QObject):
print("WHY ARE YOU DOING THIS TO ME? :(")
sys.exit(128 + signum)
def reload_config(self, _signum, _frame):
"""Reload the config."""
log.signals.info("SIGHUP received, reloading config.")
config_commands = objreg.get('config-commands', from_command=True)
try:
config_commands.config_source()
except cmdutils.CommandError as e:
log.signals.error("Error while reloading config:", exc_info=e)
def init(q_app: QApplication,
args: argparse.Namespace,