From e87b2710c8ad242bc0763e8534e9bab9479b98cd Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 3 Jan 2018 10:33:45 -0500 Subject: [PATCH] move matching regexps out of callmaster into global Change-Id: I42779b3a1b9aef8b98ddecce6fa4093589ab6d62 --- daemon/call.c | 12 ------------ daemon/call.h | 4 ---- daemon/call_interfaces.c | 25 +++++++++++++++++++++++-- daemon/call_interfaces.h | 2 ++ daemon/main.c | 2 ++ 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index 2e6b8687d..bee0f0aa8 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -610,8 +610,6 @@ next: struct callmaster *callmaster_new(struct poller *p) { struct callmaster *c; - const char *errptr; - int erroff; c = obj_alloc0("callmaster", sizeof(*c), NULL); @@ -621,16 +619,6 @@ struct callmaster *callmaster_new(struct poller *p) { c->poller = p; rwlock_init(&rtpe_callhash_lock); - c->info_re = pcre_compile("^([^:,]+)(?::(.*?))?(?:$|,)", PCRE_DOLLAR_ENDONLY | PCRE_DOTALL, &errptr, &erroff, NULL); - if (!c->info_re) - goto fail; - c->info_ree = pcre_study(c->info_re, 0, &errptr); - - c->streams_re = pcre_compile("^([\\d.]+):(\\d+)(?::(.*?))?(?:$|,)", PCRE_DOLLAR_ENDONLY | PCRE_DOTALL, &errptr, &erroff, NULL); - if (!c->streams_re) - goto fail; - c->streams_ree = pcre_study(c->streams_re, 0, &errptr); - poller_add_timer(p, callmaster_timer, &c->obj); mutex_init(&c->totalstats.total_average_lock); diff --git a/daemon/call.h b/daemon/call.h index a552a7035..ed6e26031 100644 --- a/daemon/call.h +++ b/daemon/call.h @@ -425,10 +425,6 @@ struct callmaster { struct totalstats totalstats_lastinterval; struct poller *poller; - pcre *info_re; - pcre_extra *info_ree; - pcre *streams_re; - pcre_extra *streams_ree; struct callmaster_config conf; struct timeval latest_graphite_interval_start; diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index 34ffb033e..8a8f117db 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -26,6 +26,10 @@ #include "streambuf.h" +static pcre *info_re; +static pcre_extra *info_ree; +static pcre *streams_re; +static pcre_extra *streams_ree; int trust_address_def; int dtls_passive_def; @@ -231,7 +235,7 @@ static int info_parse_func(char **a, void **ret, void *p) { } static void info_parse(const char *s, GHashTable *ih, struct callmaster *m) { - pcre_multi_match(m->info_re, m->info_ree, s, 2, info_parse_func, ih, NULL); + pcre_multi_match(info_re, info_ree, s, 2, info_parse_func, ih, NULL); } @@ -271,7 +275,7 @@ fail: static void streams_parse(const char *s, struct callmaster *m, GQueue *q) { int i; i = 0; - pcre_multi_match(m->streams_re, m->streams_ree, s, 3, streams_parse_func, &i, q); + pcre_multi_match(streams_re, streams_ree, s, 3, streams_parse_func, &i, q); } /* XXX move these somewhere else */ @@ -1230,3 +1234,20 @@ const char *call_stop_recording_ng(bencode_item_t *input, struct callmaster *m, return NULL; } + +int call_interfaces_init() { + const char *errptr; + int erroff; + + info_re = pcre_compile("^([^:,]+)(?::(.*?))?(?:$|,)", PCRE_DOLLAR_ENDONLY | PCRE_DOTALL, &errptr, &erroff, NULL); + if (!info_re) + return -1; + info_ree = pcre_study(info_re, 0, &errptr); + + streams_re = pcre_compile("^([\\d.]+):(\\d+)(?::(.*?))?(?:$|,)", PCRE_DOLLAR_ENDONLY | PCRE_DOTALL, &errptr, &erroff, NULL); + if (!streams_re) + return -1; + streams_ree = pcre_study(streams_re, 0, &errptr); + + return 0; +} diff --git a/daemon/call_interfaces.h b/daemon/call_interfaces.h index f414b489a..997329022 100644 --- a/daemon/call_interfaces.h +++ b/daemon/call_interfaces.h @@ -88,5 +88,7 @@ const char *call_stop_recording_ng(bencode_item_t *, struct callmaster *, bencod void ng_call_stats(struct call *call, const str *fromtag, const str *totag, bencode_item_t *output, struct call_stats *totals); +int call_interfaces_init(void); + #endif diff --git a/daemon/main.c b/daemon/main.c index 03bfa822c..ac27cd25b 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -493,6 +493,8 @@ static void init_everything() { interfaces_init(&interfaces); iptables_init(); control_ng_init(); + if (call_interfaces_init()) + abort(); }