main: add and use root talloc ctx

Create hlr_ctx and pass on to DB and GSUP server code.
Add call msgb_talloc_ctx_init(hlr_ctx).

Instead of printing the entire talloc context on exit, just print the hlr_ctx
upon SIGUSR1 (like our other binaries do). Otherwise we will get pages of
talloc output on each program exit as soon as we add a VTY (next patch).

Change-Id: I3c64cb4ad7a681b88c7409296ad3afeb8000e2a4
This commit is contained in:
Neels Hofmeyr 2017-01-30 13:18:23 +01:00
parent 5b581ac6eb
commit ca43e30be3
1 changed files with 7 additions and 4 deletions

View File

@ -516,6 +516,7 @@ static int read_cb(struct osmo_gsup_conn *conn, struct msgb *msg)
return 0;
}
static void *hlr_ctx = NULL;
static struct osmo_gsup_server *gs;
static void signal_hdlr(int signal)
@ -526,11 +527,12 @@ static void signal_hdlr(int signal)
osmo_gsup_server_destroy(gs);
db_close(g_dbc);
log_fini();
talloc_report_full(hlr_ctx, stderr);
exit(0);
break;
case SIGUSR1:
LOGP(DMAIN, LOGL_DEBUG, "Talloc Report due to SIGUSR1\n");
talloc_report_full(NULL, stderr);
talloc_report_full(hlr_ctx, stderr);
break;
}
}
@ -539,7 +541,8 @@ int main(int argc, char **argv)
{
int rc;
talloc_enable_leak_report_full();
hlr_ctx = talloc_named_const(NULL, 1, "OsmoHLR");
msgb_talloc_ctx_init(hlr_ctx, 0);
rc = osmo_init_logging(&hlr_log_info);
if (rc < 0) {
@ -554,13 +557,13 @@ int main(int argc, char **argv)
exit(1);
}
g_dbc = db_open(NULL, "hlr.db");
g_dbc = db_open(hlr_ctx, "hlr.db");
if (!g_dbc) {
LOGP(DMAIN, LOGL_FATAL, "Error opening database\n");
exit(1);
}
gs = osmo_gsup_server_create(NULL, NULL, 2222, read_cb);
gs = osmo_gsup_server_create(hlr_ctx, NULL, 2222, read_cb);
if (!gs) {
LOGP(DMAIN, LOGL_FATAL, "Error starting GSUP server\n");
exit(1);