aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/osmo-bsc/osmo_bsc_main.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2012-01-27 14:20:24 +0100
committerHarald Welte <laforge@gnumonks.org>2012-01-27 18:12:03 +0100
commit1dde661dd6653f21ddb003f203f8a23f201d68c9 (patch)
tree268560908c700e5cd20ab6dc589b7dbbbea3c337 /openbsc/src/osmo-bsc/osmo_bsc_main.c
parent122b6331927dd65d716d71cdf8fcb728cc2475f9 (diff)
osmo-bsc: Add configurable option to spawn + respawn osmo-bsc_mgcplaforge/mgcp-rework
If it is configured in the config file or on the VTY, osmo-bsc will fork+exec osmo-bsc_mgcp. Furthermore, if osmo-bsc_mgcp dies, osmo-bsc will re-spawn it. This also means that we can now send a SIGHUP to osmo-bsc_mgcp in the event of a Msc (re)connect, causing it to send RSIP, which in turn is required by certain call agents that forget to send a AUEP on startup to determine the endpoint state of the media gateway[s].
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 9a799c0c6..6997f3b28 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) {