mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-02-10 09:38:40 +01:00
moving set signal handler to network utils
This commit is contained in:
@@ -90,4 +90,5 @@ MacAddr InterfaceNameToMac(const std::string &inf);
|
||||
IpAddr InterfaceNameToIp(const std::string &ifn);
|
||||
void validatePortNumber(uint16_t port);
|
||||
void validatePortRange(uint16_t startPort, int numPorts);
|
||||
void setupSignalHandler(int signal, void (*handler)(int));
|
||||
} // namespace sls
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-other
|
||||
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
||||
#include "sls/network_utils.h"
|
||||
#include "sls/sls_detector_exceptions.h"
|
||||
|
||||
#include "sls/network_utils.h"
|
||||
#include <algorithm>
|
||||
#include <arpa/inet.h>
|
||||
#include <cassert>
|
||||
#include <csignal>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <ifaddrs.h>
|
||||
@@ -217,4 +218,15 @@ void validatePortRange(uint16_t startPort, int numPorts) {
|
||||
validatePortNumber(startPort + numPorts - 1);
|
||||
}
|
||||
|
||||
void setupSignalHandler(int signal, void (*handler)(int)) {
|
||||
// Catch signal SIGINT to close files and call destructors properly
|
||||
struct sigaction sa {};
|
||||
sa.sa_handler = handler;
|
||||
sigemptyset(&sa.sa_mask); // dont block additional signals
|
||||
sa.sa_flags = 0;
|
||||
if (sigaction(signal, &sa, nullptr) == -1) {
|
||||
throw RuntimeError("Could not set handler for " +
|
||||
std::string(strsignal(signal)));
|
||||
}
|
||||
}
|
||||
} // namespace sls
|
||||
|
||||
Reference in New Issue
Block a user