mirror of
https://github.com/systemd/systemd.git
synced 2025-01-11 09:18:07 +03:00
sd-event: make it easy to bind signal handling to event loop exits
By passing a NULL callback provide a simple way to make event loops exit on SIGTERM and other signals.
This commit is contained in:
parent
7ed0dd4be6
commit
59bc1fd776
@ -886,6 +886,12 @@ static int event_update_signal_fd(sd_event *e) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int signal_exit_callback(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata) {
|
||||
assert(s);
|
||||
|
||||
return sd_event_exit(sd_event_source_get_event(s), PTR_TO_INT(userdata));
|
||||
}
|
||||
|
||||
_public_ int sd_event_add_signal(
|
||||
sd_event *e,
|
||||
sd_event_source **ret,
|
||||
@ -900,11 +906,13 @@ _public_ int sd_event_add_signal(
|
||||
assert_return(e, -EINVAL);
|
||||
assert_return(sig > 0, -EINVAL);
|
||||
assert_return(sig < _NSIG, -EINVAL);
|
||||
assert_return(callback, -EINVAL);
|
||||
assert_return(ret, -EINVAL);
|
||||
assert_return(e->state != SD_EVENT_FINISHED, -ESTALE);
|
||||
assert_return(!event_pid_changed(e), -ECHILD);
|
||||
|
||||
if (!callback)
|
||||
callback = signal_exit_callback;
|
||||
|
||||
r = pthread_sigmask(SIG_SETMASK, NULL, &ss);
|
||||
if (r < 0)
|
||||
return -errno;
|
||||
|
Loading…
Reference in New Issue
Block a user