mirror of
https://github.com/systemd/systemd
synced 2024-10-07 00:30:59 +00:00
networkd: use SIGUSR2 to do a restart
The code supports SIGTERM and SIGINT to termiante the process. It would be possible to reporpose one of those signals for the restart operation, but I think it's better to use a completely different signal to avoid misunderstandings.
This commit is contained in:
parent
4ab1670f3d
commit
ab76be5581
|
@ -30,6 +30,7 @@
|
||||||
#include "ordered-set.h"
|
#include "ordered-set.h"
|
||||||
#include "path-util.h"
|
#include "path-util.h"
|
||||||
#include "set.h"
|
#include "set.h"
|
||||||
|
#include "signal-util.h"
|
||||||
#include "strv.h"
|
#include "strv.h"
|
||||||
#include "sysctl-util.h"
|
#include "sysctl-util.h"
|
||||||
#include "tmpfile-util.h"
|
#include "tmpfile-util.h"
|
||||||
|
@ -1561,6 +1562,28 @@ static int manager_dirty_handler(sd_event_source *s, void *userdata) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int signal_terminate_callback(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata) {
|
||||||
|
Manager *m = userdata;
|
||||||
|
|
||||||
|
assert(m);
|
||||||
|
m->restarting = false;
|
||||||
|
|
||||||
|
log_debug("Terminate operation initiated.");
|
||||||
|
|
||||||
|
return sd_event_exit(sd_event_source_get_event(s), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int signal_restart_callback(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata) {
|
||||||
|
Manager *m = userdata;
|
||||||
|
|
||||||
|
assert(m);
|
||||||
|
m->restarting = true;
|
||||||
|
|
||||||
|
log_debug("Restart operation initiated.");
|
||||||
|
|
||||||
|
return sd_event_exit(sd_event_source_get_event(s), 0);
|
||||||
|
}
|
||||||
|
|
||||||
int manager_new(Manager **ret) {
|
int manager_new(Manager **ret) {
|
||||||
_cleanup_(manager_freep) Manager *m = NULL;
|
_cleanup_(manager_freep) Manager *m = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
@ -1581,9 +1604,12 @@ int manager_new(Manager **ret) {
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
assert_se(sigprocmask_many(SIG_SETMASK, NULL, SIGINT, SIGTERM, SIGUSR2, -1) >= 0);
|
||||||
|
|
||||||
(void) sd_event_set_watchdog(m->event, true);
|
(void) sd_event_set_watchdog(m->event, true);
|
||||||
(void) sd_event_add_signal(m->event, NULL, SIGTERM, NULL, NULL);
|
(void) sd_event_add_signal(m->event, NULL, SIGTERM, signal_terminate_callback, m);
|
||||||
(void) sd_event_add_signal(m->event, NULL, SIGINT, NULL, NULL);
|
(void) sd_event_add_signal(m->event, NULL, SIGINT, signal_terminate_callback, m);
|
||||||
|
(void) sd_event_add_signal(m->event, NULL, SIGUSR2, signal_restart_callback, m);
|
||||||
|
|
||||||
r = sd_event_add_post(m->event, NULL, manager_dirty_handler, m);
|
r = sd_event_add_post(m->event, NULL, manager_dirty_handler, m);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
|
|
|
@ -29,6 +29,7 @@ struct Manager {
|
||||||
|
|
||||||
bool enumerating:1;
|
bool enumerating:1;
|
||||||
bool dirty:1;
|
bool dirty:1;
|
||||||
|
bool restarting:1;
|
||||||
|
|
||||||
Set *dirty_links;
|
Set *dirty_links;
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ SystemCallArchitectures=native
|
||||||
SystemCallErrorNumber=EPERM
|
SystemCallErrorNumber=EPERM
|
||||||
SystemCallFilter=@system-service
|
SystemCallFilter=@system-service
|
||||||
Type=notify
|
Type=notify
|
||||||
|
RestartKillSignal=SIGUSR2
|
||||||
User=systemd-network
|
User=systemd-network
|
||||||
WatchdogSec=3min
|
WatchdogSec=3min
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue