summaryrefslogtreecommitdiffstats
path: root/openbsc/src/osmo-bsc/osmo_bsc_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'openbsc/src/osmo-bsc/osmo_bsc_main.c')
-rw-r--r--openbsc/src/osmo-bsc/osmo_bsc_main.c44
1 files changed, 41 insertions, 3 deletions
diff --git a/openbsc/src/osmo-bsc/osmo_bsc_main.c b/openbsc/src/osmo-bsc/osmo_bsc_main.c
index 9a799c0..6997f3b 100644
--- a/openbsc/src/osmo-bsc/osmo_bsc_main.c
+++ b/openbsc/src/osmo-bsc/osmo_bsc_main.c
@@ -138,15 +138,44 @@ static struct vty_app_info vty_info = {
.is_config_node = bsc_vty_is_config_node,
};
+static int spawn_mgcp(void)
+{
+ pid_t pid;
+ struct osmo_msc_data *data = bsc_gsmnet->msc_data;
+
+ if (!data->bsc_mgcp.path) {
+ LOGP(DMGCP, LOGL_NOTICE,
+ "Config file instructs us to not start osmo-bsc_mgcp!\n");
+ return 0;
+ }
+
+ pid = fork();
+ if (pid == 0) {
+ execlp(data->bsc_mgcp.path, "osmo-bsc_mgcp", "-c",
+ data->bsc_mgcp.config_path, NULL);
+ /* only in case of error we ever end up here */
+ fprintf(stderr, "Unable to exec() mgcp `%s`: %s\n",
+ data->bsc_mgcp.path, strerror(errno));
+ exit(1);
+ } else {
+ data->bsc_mgcp.pid = pid;
+ return 0;
+ }
+}
+
extern int bsc_shutdown_net(struct gsm_network *net);
-static void signal_handler(int signal)
+static void signal_handler(int signum)
{
- fprintf(stdout, "signal %u received\n", signal);
+ fprintf(stdout, "signal %u received\n", signum);
- switch (signal) {
+ switch (signum) {
case SIGINT:
bsc_shutdown_net(bsc_gsmnet);
osmo_signal_dispatch(SS_L_GLOBAL, S_L_GLOBAL_SHUTDOWN, NULL);
+ if (bsc_gsmnet->msc_data && bsc_gsmnet->msc_data->bsc_mgcp.pid) {
+ signal(SIGCHLD, SIG_IGN);
+ kill(bsc_gsmnet->msc_data->bsc_mgcp.pid, SIGTERM);
+ }
sleep(3);
exit(0);
break;
@@ -166,6 +195,12 @@ static void signal_handler(int signal)
return;
bsc_msc_lost(bsc_gsmnet->msc_data->msc_con);
break;
+ case SIGCHLD:
+ /* bsc_mgcp seems to have died */
+ /* sleep for some time to avoid fork bomb */
+ sleep(1);
+ spawn_mgcp();
+ break;
default:
break;
}
@@ -459,8 +494,11 @@ int main(int argc, char **argv)
signal(SIGABRT, &signal_handler);
signal(SIGUSR1, &signal_handler);
signal(SIGUSR2, &signal_handler);
+ signal(SIGCHLD, &signal_handler);
osmo_init_ignore_signals();
+ spawn_mgcp();
+
if (daemonize) {
rc = osmo_daemonize();
if (rc < 0) {