bsc: Create struct osmo_msc_data to hold MSC information, handle signals
diff --git a/openbsc/include/openbsc/Makefile.am b/openbsc/include/openbsc/Makefile.am
index 234a47c..b16a1b5 100644
--- a/openbsc/include/openbsc/Makefile.am
+++ b/openbsc/include/openbsc/Makefile.am
@@ -10,7 +10,8 @@
 		crc24.h gprs_bssgp.h gprs_llc.h gprs_ns.h gprs_gmm.h \
 		gb_proxy.h gprs_sgsn.h gsm_04_08_gprs.h sgsn.h \
 		gprs_ns_frgre.h auth.h osmo_msc.h bsc_msc.h bsc_nat.h \
-		osmo_bsc_rf.h osmo_bsc.h network_listen.h bsc_nat_sccp.h
+		osmo_bsc_rf.h osmo_bsc.h network_listen.h bsc_nat_sccp.h \
+		osmo_msc_data.h
 
 openbsc_HEADERS = gsm_04_08.h meas_rep.h bsc_api.h
 openbscdir = $(includedir)/openbsc
diff --git a/openbsc/include/openbsc/gsm_data.h b/openbsc/include/openbsc/gsm_data.h
index 31e1152..e0f7c70 100644
--- a/openbsc/include/openbsc/gsm_data.h
+++ b/openbsc/include/openbsc/gsm_data.h
@@ -3,6 +3,8 @@
 
 #include <sys/types.h>
 
+struct osmo_msc_data;
+
 enum gsm_phys_chan_config {
 	GSM_PCHAN_NONE,
 	GSM_PCHAN_CCCH,
@@ -722,7 +724,8 @@
 	/* Use a TCH for handling requests of type paging any */
 	int pag_any_tch;
 
-	int msc_prio;
+	/* MSC data in case we are a true BSC */
+	struct osmo_msc_data *msc_data;
 };
 
 #define SMS_HDR_SIZE	128
diff --git a/openbsc/include/openbsc/osmo_msc_data.h b/openbsc/include/openbsc/osmo_msc_data.h
new file mode 100644
index 0000000..4a84f74
--- /dev/null
+++ b/openbsc/include/openbsc/osmo_msc_data.h
@@ -0,0 +1,33 @@
+/*
+ * Data for the true BSC
+ *
+ * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
+ * (C) 2010 by On-Waves
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#ifndef _OSMO_MSC_DATA_H
+#define _OSMO_MSC_DATA_H
+
+#include "bsc_msc.h"
+
+struct osmo_msc_data {
+	struct bsc_msc_connection *msc_con;
+};
+
+#endif
diff --git a/openbsc/src/bsc/osmo_bsc_main.c b/openbsc/src/bsc/osmo_bsc_main.c
index b35d537..062bbf8 100644
--- a/openbsc/src/bsc/osmo_bsc_main.c
+++ b/openbsc/src/bsc/osmo_bsc_main.c
@@ -22,6 +22,8 @@
 #include <openbsc/debug.h>
 #include <openbsc/gsm_data.h>
 #include <openbsc/osmo_bsc_rf.h>
+#include <openbsc/osmo_msc_data.h>
+#include <openbsc/signal.h>
 #include <openbsc/vty.h>
 
 #include <osmocore/talloc.h>
@@ -32,9 +34,12 @@
 #define _GNU_SOURCE
 #include <getopt.h>
 
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
+#include <unistd.h>
+
 
 #include "bscconfig.h"
 
@@ -141,6 +146,38 @@
 	.is_config_node	= bsc_vty_is_config_node,
 };
 
+extern int bsc_shutdown_net(struct gsm_network *net);
+static void signal_handler(int signal)
+{
+	fprintf(stdout, "signal %u received\n", signal);
+
+	switch (signal) {
+	case SIGINT:
+		bsc_shutdown_net(bsc_gsmnet);
+		dispatch_signal(SS_GLOBAL, S_GLOBAL_SHUTDOWN, NULL);
+		sleep(3);
+		exit(0);
+		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:
+		talloc_report(tall_vty_ctx, stderr);
+		talloc_report_full(tall_bsc_ctx, stderr);
+		break;
+	case SIGUSR2:
+		if (!bsc_gsmnet->msc_data)
+			return;
+		if (!bsc_gsmnet->msc_data->msc_con)
+			return;
+		if (!bsc_gsmnet->msc_data->msc_con->is_connected)
+			return;
+		bsc_msc_lost(bsc_gsmnet->msc_data->msc_con);
+		break;
+	default:
+		break;
+	}
+}
 
 int main(int argc, char **argv)
 {
@@ -189,6 +226,12 @@
 		}
 	}
 
+	signal(SIGINT, &signal_handler);
+	signal(SIGABRT, &signal_handler);
+	signal(SIGUSR1, &signal_handler);
+	signal(SIGUSR2, &signal_handler);
+	signal(SIGPIPE, SIG_IGN);
+
 	if (daemonize) {
 		rc = osmo_daemonize();
 		if (rc < 0) {
diff --git a/openbsc/src/gsm_data.c b/openbsc/src/gsm_data.c
index 526b177..b7d39b4 100644
--- a/openbsc/src/gsm_data.c
+++ b/openbsc/src/gsm_data.c
@@ -33,6 +33,7 @@
 #include <osmocore/statistics.h>
 
 #include <openbsc/gsm_data.h>
+#include <openbsc/osmo_msc_data.h>
 #include <openbsc/abis_nm.h>
 
 void *tall_bsc_ctx;
@@ -254,6 +255,12 @@
 	if (!net)
 		return NULL;
 
+	net->msc_data = talloc_zero(net, struct osmo_msc_data);
+	if (!net->msc_data) {
+		talloc_free(net);
+		return NULL;
+	}
+
 	net->country_code = country_code;
 	net->network_code = network_code;
 	net->num_bts = 0;