mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-31 22:15:23 +00:00
[3405] Properly initialize sigaction data for SignalSet object.
Had to use memset to reset sa_action structure. Without that the signal handled wasn't installed correctly because of the random data in the sigaction structure and caused unit tests to fail.
This commit is contained in:
@@ -101,7 +101,9 @@ void
|
|||||||
SignalSet::add(const int sig) {
|
SignalSet::add(const int sig) {
|
||||||
insert(sig);
|
insert(sig);
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
|
memset(&sa, 0, sizeof(sa));
|
||||||
sa.sa_handler = internalHandler;
|
sa.sa_handler = internalHandler;
|
||||||
|
sigfillset(&sa.sa_mask);
|
||||||
if (sigaction(sig, &sa, 0) < 0) {
|
if (sigaction(sig, &sa, 0) < 0) {
|
||||||
erase(sig);
|
erase(sig);
|
||||||
isc_throw(SignalSetError, "failed to register a signal handler for"
|
isc_throw(SignalSetError, "failed to register a signal handler for"
|
||||||
@@ -209,7 +211,9 @@ SignalSet::remove(const int sig) {
|
|||||||
// Unregister only if we own this signal.
|
// Unregister only if we own this signal.
|
||||||
if (local_signals_.find(sig) != local_signals_.end()) {
|
if (local_signals_.find(sig) != local_signals_.end()) {
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
|
memset(&sa, 0, sizeof(sa));
|
||||||
sa.sa_handler = SIG_DFL;
|
sa.sa_handler = SIG_DFL;
|
||||||
|
sigfillset(&sa.sa_mask);
|
||||||
if (sigaction(sig, &sa, 0) < 0) {
|
if (sigaction(sig, &sa, 0) < 0) {
|
||||||
isc_throw(SignalSetError, "unable to restore original signal"
|
isc_throw(SignalSetError, "unable to restore original signal"
|
||||||
" handler for signal: " << sig);
|
" handler for signal: " << sig);
|
||||||
|
@@ -78,7 +78,7 @@ int SignalSetTest::signum_ = -1;
|
|||||||
/// Check that the signals are recorded by the signal handlers.
|
/// Check that the signals are recorded by the signal handlers.
|
||||||
TEST_F(SignalSetTest, twoSignals) {
|
TEST_F(SignalSetTest, twoSignals) {
|
||||||
// Register handlers for two signals.
|
// Register handlers for two signals.
|
||||||
signal_set_.reset(new SignalSet(SIGHUP, SIGINT));
|
ASSERT_NO_THROW(signal_set_.reset(new SignalSet(SIGHUP, SIGINT)));
|
||||||
// Send SIGHUP signal to the process.
|
// Send SIGHUP signal to the process.
|
||||||
ASSERT_EQ(0, raise(SIGHUP));
|
ASSERT_EQ(0, raise(SIGHUP));
|
||||||
// The SIGHUP should be the next one in the queue to be handled.
|
// The SIGHUP should be the next one in the queue to be handled.
|
||||||
|
Reference in New Issue
Block a user