track libulfius and jansson memory allocations with talloc
Change-Id: I0ad63a79a806b420ea0de42b67726da36ebac828
This commit is contained in:
parent
1b86ba81a0
commit
0c50c34f18
|
@ -45,6 +45,7 @@ AC_ARG_ENABLE([remsim-server],[AS_HELP_STRING([--disable-remsim-server], [Build
|
|||
[osmo_ac_build_server="$enableval"],[osmo_ac_build_server="yes"])
|
||||
if test "$osmo_ac_build_server" = "yes"; then
|
||||
PKG_CHECK_MODULES(ULFIUS, libulfius)
|
||||
PKG_CHECK_MODULES(ORCANIA, liborcania)
|
||||
PKG_CHECK_MODULES(JANSSON, jansson)
|
||||
AC_DEFINE(BUILD_SERVER, 1, [Define if we want to build osmo-remsim-server])
|
||||
fi
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
AM_CFLAGS = -Wall -I$(top_srcdir)/include -I$(top_builddir)/include -I$(top_srcdir)/src \
|
||||
-I$(top_srcdir)/include/osmocom/rspro \
|
||||
$(OSMOCORE_CFLAGS) $(OSMOGSM_CFLAGS) $(OSMOABIS_CFLAGS) \
|
||||
$(ULFIUS_CFLAGS) $(JANSSON_CFLAGS)
|
||||
$(ULFIUS_CFLAGS) $(JANSSON_CFLAGS) $(ORCANIA_CFLAGS)
|
||||
|
||||
noinst_HEADERS = rspro_server.h rest_api.h
|
||||
|
||||
|
@ -11,7 +11,7 @@ bin_PROGRAMS = osmo-remsim-server
|
|||
osmo_remsim_server_SOURCES = remsim_server.c rspro_server.c rest_api.c \
|
||||
../rspro_util.c ../slotmap.c ../debug.c
|
||||
osmo_remsim_server_LDADD = $(OSMOCORE_LIBS) $(OSMOGSM_LIBS) $(OSMOABIS_LIBS) \
|
||||
$(ULFIUS_LIBS) $(JANSSON_LIBS) \
|
||||
$(ULFIUS_LIBS) $(JANSSON_LIBS) $(ORCANIA_LIBS) \
|
||||
$(top_builddir)/src/libosmo-rspro.la
|
||||
|
||||
# as suggested in http://lists.gnu.org/archive/html/automake/2009-03/msg00011.html
|
||||
|
|
|
@ -27,10 +27,12 @@ static void handle_sig_usr1(int signal)
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
void *talloc_rest_ctx;
|
||||
int rc;
|
||||
|
||||
g_tall_ctx = talloc_named_const(NULL, 0, "global");
|
||||
talloc_asn1_ctx = talloc_named_const(g_tall_ctx, 0, "asn1");
|
||||
talloc_rest_ctx = talloc_named_const(g_tall_ctx, 0, "rest");
|
||||
msgb_talloc_ctx_init(g_tall_ctx, 0);
|
||||
|
||||
osmo_init_logging2(g_tall_ctx, &log_info);
|
||||
|
@ -56,7 +58,7 @@ int main(int argc, char **argv)
|
|||
|
||||
signal(SIGUSR1, handle_sig_usr1);
|
||||
|
||||
rc = rest_api_init(9997);
|
||||
rc = rest_api_init(talloc_rest_ctx, 9997);
|
||||
if (rc < 0)
|
||||
goto out_eventfd;
|
||||
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include <jansson.h>
|
||||
#include <ulfius.h>
|
||||
#include <orcania.h>
|
||||
|
||||
#include <osmocom/core/utils.h>
|
||||
#include <osmocom/core/linuxlist.h>
|
||||
|
@ -461,13 +463,43 @@ static const struct _u_endpoint api_endpoints[] = {
|
|||
};
|
||||
|
||||
static struct _u_instance g_instance;
|
||||
static pthread_mutex_t g_tall_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static void *g_tall_rest;
|
||||
|
||||
int rest_api_init(uint16_t port)
|
||||
static void *my_o_malloc(size_t sz)
|
||||
{
|
||||
void *obj;
|
||||
pthread_mutex_lock(&g_tall_lock);
|
||||
obj = talloc_size(g_tall_rest, sz);
|
||||
pthread_mutex_unlock(&g_tall_lock);
|
||||
return obj;
|
||||
}
|
||||
|
||||
static void *my_o_realloc(void *obj, size_t sz)
|
||||
{
|
||||
pthread_mutex_lock(&g_tall_lock);
|
||||
obj = talloc_realloc_size(g_tall_rest, obj, sz);
|
||||
pthread_mutex_unlock(&g_tall_lock);
|
||||
return obj;
|
||||
}
|
||||
|
||||
static void my_o_free(void *obj)
|
||||
{
|
||||
pthread_mutex_lock(&g_tall_lock);
|
||||
talloc_free(obj);
|
||||
pthread_mutex_unlock(&g_tall_lock);
|
||||
}
|
||||
|
||||
int rest_api_init(void *ctx, uint16_t port)
|
||||
{
|
||||
int i;
|
||||
|
||||
g_tall_rest = ctx;
|
||||
o_set_alloc_funcs(my_o_malloc, my_o_realloc, my_o_free);
|
||||
|
||||
if (ulfius_init_instance(&g_instance, port, NULL, NULL) != U_OK)
|
||||
return -1;
|
||||
g_instance.mhd_response_copy_data = 1;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(api_endpoints); i++)
|
||||
ulfius_add_endpoint(&g_instance, &api_endpoints[i]);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
int rest_api_init(uint16_t port);
|
||||
int rest_api_init(void *ctx, uint16_t port);
|
||||
void rest_api_fini(void);
|
||||
|
|
Loading…
Reference in New Issue