bsc: Move the signal handling code over to the bsc.c
This commit is contained in:
parent
2d4891ff8c
commit
5cd45e16ef
43
src/bsc.c
43
src/bsc.c
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include <bsc_data.h>
|
||||
#include <cellmgr_debug.h>
|
||||
#include <msc_connection.h>
|
||||
#include <mtp_level3.h>
|
||||
#include <mtp_pcap.h>
|
||||
|
||||
|
@ -34,6 +35,8 @@
|
|||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
|
@ -80,6 +83,42 @@ struct bsc_data *bsc_data_create()
|
|||
return bsc;
|
||||
}
|
||||
|
||||
static void sigint()
|
||||
{
|
||||
static pthread_mutex_t exit_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static int handled = 0;
|
||||
|
||||
struct mtp_link_set *set;
|
||||
|
||||
/* failed to lock */
|
||||
if (pthread_mutex_trylock(&exit_mutex) != 0)
|
||||
return;
|
||||
if (handled)
|
||||
goto out;
|
||||
|
||||
printf("Terminating.\n");
|
||||
handled = 1;
|
||||
if (bsc) {
|
||||
llist_for_each_entry(set, &bsc->linksets, entry)
|
||||
link_shutdown_all(set);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
|
||||
out:
|
||||
pthread_mutex_unlock(&exit_mutex);
|
||||
}
|
||||
|
||||
static void sigusr2()
|
||||
{
|
||||
struct msc_connection *msc;
|
||||
printf("Closing the MSC connection on demand.\n");
|
||||
|
||||
llist_for_each_entry(msc, &bsc->mscs, entry)
|
||||
msc_close_connection(msc);
|
||||
}
|
||||
|
||||
|
||||
static void print_usage(const char *arg)
|
||||
{
|
||||
printf("Usage: %s\n", arg);
|
||||
|
@ -139,4 +178,8 @@ void handle_options(int argc, char **argv)
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
signal(SIGINT, sigint);
|
||||
signal(SIGUSR2, sigusr2);
|
||||
}
|
||||
|
|
40
src/main.c
40
src/main.c
|
@ -38,8 +38,6 @@
|
|||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
static struct log_target *stderr_target;
|
||||
|
||||
char *config = "cellmgr_ng.cfg";
|
||||
|
@ -48,41 +46,6 @@ struct bsc_data *bsc;
|
|||
extern void cell_vty_init(void);
|
||||
extern void handle_options(int argc, char **argv);
|
||||
|
||||
static void sigint()
|
||||
{
|
||||
static pthread_mutex_t exit_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static int handled = 0;
|
||||
|
||||
struct mtp_link_set *set;
|
||||
|
||||
/* failed to lock */
|
||||
if (pthread_mutex_trylock(&exit_mutex) != 0)
|
||||
return;
|
||||
if (handled)
|
||||
goto out;
|
||||
|
||||
printf("Terminating.\n");
|
||||
handled = 1;
|
||||
if (bsc) {
|
||||
llist_for_each_entry(set, &bsc->linksets, entry)
|
||||
link_shutdown_all(set);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
|
||||
out:
|
||||
pthread_mutex_unlock(&exit_mutex);
|
||||
}
|
||||
|
||||
static void sigusr2()
|
||||
{
|
||||
struct msc_connection *msc;
|
||||
printf("Closing the MSC connection on demand.\n");
|
||||
|
||||
llist_for_each_entry(msc, &bsc->mscs, entry)
|
||||
msc_close_connection(msc);
|
||||
}
|
||||
|
||||
static void bsc_msc_forward_init(struct msc_connection *msc)
|
||||
{
|
||||
msc->ip = talloc_strdup(msc, "127.0.0.1");
|
||||
|
@ -129,9 +92,6 @@ int main(int argc, char **argv)
|
|||
|
||||
handle_options(argc, argv);
|
||||
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
signal(SIGINT, sigint);
|
||||
signal(SIGUSR2, sigusr2);
|
||||
srand(time(NULL));
|
||||
|
||||
cell_vty_init();
|
||||
|
|
|
@ -70,31 +70,6 @@ struct bsc_data *bsc;
|
|||
extern void cell_vty_init(void);
|
||||
extern void handle_options(int argc, char **argv);
|
||||
|
||||
static void sigint()
|
||||
{
|
||||
static pthread_mutex_t exit_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static int handled = 0;
|
||||
|
||||
struct mtp_link_set *set;
|
||||
|
||||
/* failed to lock */
|
||||
if (pthread_mutex_trylock(&exit_mutex) != 0)
|
||||
return;
|
||||
if (handled)
|
||||
goto out;
|
||||
|
||||
printf("Terminating.\n");
|
||||
handled = 1;
|
||||
if (bsc) {
|
||||
llist_for_each_entry(set, &bsc->linksets, entry)
|
||||
link_shutdown_all(set);
|
||||
}
|
||||
exit(0);
|
||||
|
||||
out:
|
||||
pthread_mutex_unlock(&exit_mutex);
|
||||
}
|
||||
|
||||
static struct mtp_link_set *find_link_set(struct bsc_data *bsc,
|
||||
int len, const char *buf)
|
||||
{
|
||||
|
@ -250,8 +225,6 @@ int main(int argc, char **argv)
|
|||
|
||||
handle_options(argc, argv);
|
||||
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
signal(SIGINT, sigint);
|
||||
srand(time(NULL));
|
||||
|
||||
cell_vty_init();
|
||||
|
@ -332,6 +305,9 @@ void msc_mgcp_reset(struct msc_connection *msc)
|
|||
void msc_send_reset(struct msc_connection *bsc)
|
||||
{
|
||||
}
|
||||
void msc_close_connection(struct msc_connection *bsc)
|
||||
{
|
||||
}
|
||||
void app_resources_released(struct ss7_application *ss7)
|
||||
{
|
||||
}
|
||||
|
|
Reference in New Issue