mirror of https://github.com/pvnis/srsRAN_4G.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.6 KiB
C
72 lines
1.6 KiB
C
4 years ago
|
/**
|
||
5 years ago
|
*
|
||
4 years ago
|
* \section COPYRIGHT
|
||
5 years ago
|
*
|
||
4 years ago
|
* Copyright 2013-2021 Software Radio Systems Limited
|
||
5 years ago
|
*
|
||
4 years ago
|
* By using this file, you agree to the terms and conditions set
|
||
|
* forth in the LICENSE file which can be found at the top level of
|
||
|
* the distribution.
|
||
5 years ago
|
*
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* @file signal_handler.h
|
||
4 years ago
|
* @brief Common signal handling methods for all srsRAN applications.
|
||
5 years ago
|
*/
|
||
|
|
||
4 years ago
|
#ifndef SRSRAN_SIGNAL_HANDLER_H
|
||
|
#define SRSRAN_SIGNAL_HANDLER_H
|
||
5 years ago
|
|
||
4 years ago
|
#include "srsran/srslog/sink.h"
|
||
|
#include "srsran/srslog/srslog.h"
|
||
5 years ago
|
#include <signal.h>
|
||
|
#include <stdio.h>
|
||
|
|
||
|
#ifdef __cplusplus
|
||
|
extern "C" {
|
||
|
#endif // __cplusplus
|
||
|
|
||
4 years ago
|
#define SRSRAN_TERM_TIMEOUT_S (5)
|
||
5 years ago
|
|
||
|
// static vars required by signal handling
|
||
4 years ago
|
static srslog::sink* log_sink = nullptr;
|
||
|
static bool running = true;
|
||
5 years ago
|
|
||
4 years ago
|
static void srsran_signal_handler(int signal)
|
||
5 years ago
|
{
|
||
|
switch (signal) {
|
||
|
case SIGALRM:
|
||
4 years ago
|
fprintf(stderr, "Couldn't stop after %ds. Forcing exit.\n", SRSRAN_TERM_TIMEOUT_S);
|
||
4 years ago
|
srslog::flush();
|
||
5 years ago
|
//:TODO: refactor the sighandler, should not depend on log utilities
|
||
|
if (log_sink) {
|
||
|
log_sink->flush();
|
||
|
}
|
||
5 years ago
|
raise(SIGKILL);
|
||
5 years ago
|
default:
|
||
|
// all other registered signals try to stop the app gracefully
|
||
|
if (running) {
|
||
|
running = false;
|
||
|
fprintf(stdout, "Stopping ..\n");
|
||
4 years ago
|
alarm(SRSRAN_TERM_TIMEOUT_S);
|
||
5 years ago
|
} else {
|
||
|
// already waiting for alarm to go off ..
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
4 years ago
|
void srsran_register_signal_handler()
|
||
5 years ago
|
{
|
||
4 years ago
|
signal(SIGINT, srsran_signal_handler);
|
||
|
signal(SIGTERM, srsran_signal_handler);
|
||
|
signal(SIGHUP, srsran_signal_handler);
|
||
|
signal(SIGALRM, srsran_signal_handler);
|
||
5 years ago
|
}
|
||
|
|
||
|
#ifdef __cplusplus
|
||
|
}
|
||
|
#endif // __cplusplus
|
||
4 years ago
|
#endif // SRSRAN_SIGNAL_HANDLER_H
|