Adding signal handler to allow clean exit of PCU

The signal handler will end the main loop, so clean exit is performed.

The allocated memory is dumped in order to detect memory leaks.

All talloc functions use tall_pcu_ctx context instead of NULL, to track
memory leaks.
This commit is contained in:
Andreas Eversberg 2012-07-13 14:00:21 +02:00
parent b8695f290a
commit e266bd48ac
4 changed files with 58 additions and 4 deletions

View File

@ -35,6 +35,8 @@ extern "C" {
#include <pcuif_proto.h>
}
extern void *tall_pcu_ctx;
struct femtol1_hdl {
struct gsm_time gsm_time;
uint32_t hLayer1; /* handle to the L1 instance in the DSP */
@ -142,7 +144,7 @@ int pcu_l1if_open()
int rc;
/* allocate new femtol1_handle */
fl1h = talloc_zero(NULL, struct femtol1_hdl);
fl1h = talloc_zero(tall_pcu_ctx, struct femtol1_hdl);
INIT_LLIST_HEAD(&fl1h->wlc_list);
l1fh->fl1h = fl1h;

View File

@ -37,6 +37,8 @@ extern "C" {
#include <gprs_bssgp_pcu.h>
#include <pcuif_proto.h>
extern void *tall_pcu_ctx;
// Variable for storage current FN.
int frame_number;

View File

@ -25,6 +25,7 @@
#include <gprs_debug.h>
#include <unistd.h>
#include <getopt.h>
#include <signal.h>
extern "C" {
#include "pcu_vty.h"
#include <osmocom/vty/telnet_interface.h>
@ -38,6 +39,7 @@ static int config_given = 0;
static const char *config_file = "osmo-pcu.cfg";
extern struct vty_app_info pcu_vty_info;
void *tall_pcu_ctx;
static int quit = 0;
static void print_help()
{
@ -93,6 +95,39 @@ static void handle_options(int argc, char **argv)
}
}
void sighandler(int sigset)
{
if (sigset == SIGHUP || sigset == SIGPIPE)
return;
fprintf(stderr, "Signal %d received.\n", sigset);
switch (sigset) {
case SIGINT:
/* If another signal is received afterwards, the program
* is terminated without finishing shutdown process.
*/
signal(SIGINT, SIG_DFL);
signal(SIGHUP, SIG_DFL);
signal(SIGTERM, SIG_DFL);
signal(SIGPIPE, SIG_DFL);
signal(SIGABRT, SIG_DFL);
signal(SIGUSR1, SIG_DFL);
signal(SIGUSR2, SIG_DFL);
quit = 1;
break;
case SIGABRT:
/* in case of abort, we want to obtain a talloc report
* and then return to the caller, who will abort the process
*/
case SIGUSR1:
case SIGUSR2:
talloc_report_full(tall_pcu_ctx, stderr);
break;
}
}
int main(int argc, char *argv[])
{
struct gprs_rlcmac_bts *bts;
@ -118,6 +153,8 @@ int main(int argc, char *argv[])
bts->n3103 = 4;
bts->n3105 = 8;
msgb_set_talloc_ctx(tall_pcu_ctx);
osmo_init_logging(&gprs_log_info);
vty_init(&pcu_vty_info);
@ -151,8 +188,15 @@ int main(int argc, char *argv[])
if (rc < 0)
return rc;
while (1)
{
signal(SIGINT, sighandler);
signal(SIGHUP, sighandler);
signal(SIGTERM, sighandler);
signal(SIGPIPE, sighandler);
signal(SIGABRT, sighandler);
signal(SIGUSR1, sighandler);
signal(SIGUSR2, sighandler);
while (!quit) {
osmo_gsm_timers_check();
osmo_gsm_timers_prepare();
osmo_gsm_timers_update();
@ -160,8 +204,13 @@ int main(int argc, char *argv[])
osmo_select_main(0);
}
telnet_exit();
pcu_l1if_close();
talloc_free(gprs_rlcmac_bts);
talloc_report_full(tall_pcu_ctx, stderr);
talloc_free(tall_pcu_ctx);
return 0;

View File

@ -37,6 +37,7 @@ extern "C" {
#include <gprs_bssgp_pcu.h>
#include <pcuif_proto.h>
extern void *tall_pcu_ctx;
/*
* SYSMO-PCU socket functions
@ -219,7 +220,7 @@ int pcu_l1if_open(void)
state = pcu_sock_state;
if (!state) {
state = talloc_zero(NULL, struct pcu_sock_state);
state = talloc_zero(tall_pcu_ctx, struct pcu_sock_state);
if (!state)
return -ENOMEM;
INIT_LLIST_HEAD(&state->upqueue);