From dffbddb2d6c8c52a420bd6b88bc1fe70b5658c44 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 3 Jan 2018 10:48:41 -0500 Subject: [PATCH] don't use g_ prefix for global variables Change-Id: Ifd843b01d7fccf294f97fdf48308c71268e1b8ae --- daemon/aux.c | 4 +-- daemon/aux.h | 4 +-- daemon/call.c | 34 ++++++++++----------- daemon/call_interfaces.c | 4 +-- daemon/control_tcp.c | 2 +- daemon/cookie_cache.c | 6 ++-- daemon/dtls.c | 2 +- daemon/graphite.c | 66 ++++++++++++++++++++-------------------- daemon/ice.c | 34 ++++++++++----------- daemon/iptables.c | 20 ++++++------ daemon/iptables.h | 2 +- daemon/main.c | 8 ++--- daemon/media_socket.c | 4 +-- daemon/poller.c | 12 ++++---- daemon/poller.h | 4 --- daemon/recording.c | 4 +-- daemon/redis.c | 10 +++--- daemon/statistics.c | 2 +- daemon/streambuf.c | 8 ++--- 19 files changed, 113 insertions(+), 117 deletions(-) diff --git a/daemon/aux.c b/daemon/aux.c index 459f781a6..c01c8c027 100644 --- a/daemon/aux.c +++ b/daemon/aux.c @@ -34,8 +34,8 @@ static cond_t threads_cond = COND_STATIC_INIT; static struct thread_buf __thread t_bufs[NUM_THREAD_BUFS]; static int __thread t_buf_idx; -__thread struct timeval g_now; -volatile int g_shutdown; +__thread struct timeval rtpe_now; +volatile int rtpe_shutdown; #ifdef NEED_ATOMIC64_MUTEX mutex_t __atomic64_mutex = MUTEX_STATIC_INIT; diff --git a/daemon/aux.h b/daemon/aux.h index 91315274b..4feb1250b 100644 --- a/daemon/aux.h +++ b/daemon/aux.h @@ -62,8 +62,8 @@ G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gint)); \ /*** GLOBALS ***/ -extern __thread struct timeval g_now; -extern volatile int g_shutdown; +extern __thread struct timeval rtpe_now; +extern volatile int rtpe_shutdown; diff --git a/daemon/call.c b/daemon/call.c index bee0f0aa8..92401f2fb 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -142,7 +142,7 @@ static int call_timer_delete_monologues(struct call *c) { if (!ml->deleted) continue; - if (ml->deleted > poller_now) { + if (ml->deleted > rtpe_now.tv_sec) { if (!min_deleted || ml->deleted < min_deleted) min_deleted = ml->deleted; continue; @@ -188,7 +188,7 @@ static void call_timer_iterator(gpointer data, gpointer user_data) { rwlock_lock_r(&cm->conf.config_lock); // final timeout applicable to all calls (own and foreign) - if (cm->conf.final_timeout && poller_now >= (c->created.tv_sec + cm->conf.final_timeout)) { + if (cm->conf.final_timeout && rtpe_now.tv_sec >= (c->created.tv_sec + cm->conf.final_timeout)) { ilog(LOG_INFO, "Closing call due to final timeout"); tmp_t_reason = FINAL_TIMEOUT; for (it = c->monologues.head; it; it = it->next) { @@ -205,11 +205,11 @@ static void call_timer_iterator(gpointer data, gpointer user_data) { goto out; } - if (c->deleted && poller_now >= c->deleted + if (c->deleted && rtpe_now.tv_sec >= c->deleted && c->last_signal <= c->deleted) goto delete; - if (c->ml_deleted && poller_now >= c->ml_deleted) { + if (c->ml_deleted && rtpe_now.tv_sec >= c->ml_deleted) { if (call_timer_delete_monologues(c)) goto delete; } @@ -250,7 +250,7 @@ no_sfd: tmp_t_reason = SILENT_TIMEOUT; } - if (poller_now - atomic64_get(timestamp) < check) + if (rtpe_now.tv_sec - atomic64_get(timestamp) < check) good = 1; next: @@ -525,7 +525,7 @@ static void callmaster_timer(void *ptr) { if (ke->stats.packets != atomic64_get(&ps->kernel_stats.packets)) - atomic64_set(&ps->last_packet, poller_now); + atomic64_set(&ps->last_packet, rtpe_now.tv_sec); ps->stats.in_tos_tclass = ke->stats.in_tos; @@ -626,7 +626,7 @@ struct callmaster *callmaster_new(struct poller *p) { mutex_init(&c->totalstats_interval.managed_sess_lock); mutex_init(&c->totalstats_interval.total_calls_duration_lock); - c->totalstats.started = poller_now; + c->totalstats.started = rtpe_now.tv_sec; //c->totalstats_interval.managed_sess_min = 0; // already zeroed //c->totalstats_interval.managed_sess_max = 0; @@ -834,7 +834,7 @@ struct packet_stream *__packet_stream_new(struct call *call) { mutex_init(&stream->in_lock); mutex_init(&stream->out_lock); stream->call = call; - atomic64_set_na(&stream->last_packet, poller_now); + atomic64_set_na(&stream->last_packet, rtpe_now.tv_sec); stream->rtp_stats = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, __rtp_stats_free); recording_init_stream(stream); @@ -1508,7 +1508,7 @@ int monologue_offer_answer(struct call_monologue *other_ml, GQueue *streams, monologue = other_ml->active_dialogue; call = monologue->call; - call->last_signal = poller_now; + call->last_signal = rtpe_now.tv_sec; call->deleted = 0; __C_DBG("this="STR_FORMAT" other="STR_FORMAT, STR_FMT(&monologue->tag), STR_FMT(&other_ml->tag)); @@ -1756,7 +1756,7 @@ static struct timeval add_ongoing_calls_dur_in_interval(struct callmaster *m, if (timercmp(interval_start, &ml->started, >)) { timeval_add(&res, &res, interval_duration); } else { - timeval_subtract(&call_duration, &g_now, &ml->started); + timeval_subtract(&call_duration, &rtpe_now, &ml->started); timeval_add(&res, &res, &call_duration); } } @@ -1820,8 +1820,8 @@ void call_destroy(struct call *c) { ml->label.s ? " (label '" : "", STR_FMT(ml->label.s ? &ml->label : &STR_EMPTY), ml->label.s ? "')" : "", - (unsigned int) (poller_now - ml->created) / 60, - (unsigned int) (poller_now - ml->created) % 60, + (unsigned int) (rtpe_now.tv_sec - ml->created) / 60, + (unsigned int) (rtpe_now.tv_sec - ml->created) % 60, STR_FMT(&ml->viabranch), ml->active_dialogue ? ml->active_dialogue->tag.len : 6, ml->active_dialogue ? ml->active_dialogue->tag.s : "(none)"); @@ -1860,7 +1860,7 @@ void call_destroy(struct call *c) { atomic64_get(&ps->stats.packets), atomic64_get(&ps->stats.bytes), atomic64_get(&ps->stats.errors), - g_now.tv_sec - atomic64_get(&ps->last_packet)); + rtpe_now.tv_sec - atomic64_get(&ps->last_packet)); statistics_update_totals(m,ps); @@ -2024,7 +2024,7 @@ static struct call *call_create(const str *callid, struct callmaster *m) { c->tags = g_hash_table_new(str_hash, str_equal); c->viabranches = g_hash_table_new(str_hash, str_equal); call_str_cpy(c, &c->callid, callid); - c->created = g_now; + c->created = rtpe_now; c->dtls_cert = dtls_cert(); c->tos = m->conf.default_tos; c->ssrc_hash = create_ssrc_hash(); @@ -2104,7 +2104,7 @@ struct call_monologue *__monologue_create(struct call *call) { ret = uid_slice_alloc0(ret, &call->monologues); ret->call = call; - ret->created = poller_now; + ret->created = rtpe_now.tv_sec; ret->other_tags = g_hash_table_new(str_hash, str_equal); g_queue_init(&ret->medias); @@ -2428,7 +2428,7 @@ do_delete: ilog(LOG_INFO, "Scheduling deletion of call branch '"STR_FORMAT"' " "(via-branch '"STR_FORMAT"') in %d seconds", STR_FMT(&ml->tag), STR_FMT0(branch), delete_delay); - ml->deleted = poller_now + delete_delay; + ml->deleted = rtpe_now.tv_sec + delete_delay; if (!c->ml_deleted || c->ml_deleted > ml->deleted) c->ml_deleted = ml->deleted; } @@ -2443,7 +2443,7 @@ do_delete: del_all: if (delete_delay > 0) { ilog(LOG_INFO, "Scheduling deletion of entire call in %d seconds", delete_delay); - c->deleted = poller_now + delete_delay; + c->deleted = rtpe_now.tv_sec + delete_delay; rwlock_unlock_w(&c->master_lock); } else { diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index 8a8f117db..dc91ca24c 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -398,7 +398,7 @@ str *call_query_udp(char **out, struct callmaster *m) { rwlock_lock_r(&m->conf.config_lock); ret = str_sprintf("%s %lld "UINT64F" "UINT64F" "UINT64F" "UINT64F"\n", out[RE_UDP_COOKIE], - (long long int) m->conf.silent_timeout - (poller_now - stats.last_packet), + (long long int) m->conf.silent_timeout - (rtpe_now.tv_sec - stats.last_packet), atomic64_get_na(&stats.totals[0].packets), atomic64_get_na(&stats.totals[1].packets), atomic64_get_na(&stats.totals[2].packets), atomic64_get_na(&stats.totals[3].packets)); rwlock_unlock_r(&m->conf.config_lock); @@ -437,7 +437,7 @@ static void call_status_iterator(struct call *c, struct streambuf_stream *s) { streambuf_printf(s->outbuf, "session "STR_FORMAT" - - - - %lli\n", STR_FMT(&c->callid), - timeval_diff(&g_now, &c->created) / 1000000); + timeval_diff(&rtpe_now, &c->created) / 1000000); /* XXX restore function */ diff --git a/daemon/control_tcp.c b/daemon/control_tcp.c index 6ffb29d3f..c5a893fdb 100644 --- a/daemon/control_tcp.c +++ b/daemon/control_tcp.c @@ -117,7 +117,7 @@ static int control_stream_parse(struct streambuf_stream *s, char *line) { static void control_stream_timer(struct streambuf_stream *s) { - if ((poller_now - s->inbuf->active) >= 60 || (poller_now - s->outbuf->active) >= 60) + if ((rtpe_now.tv_sec - s->inbuf->active) >= 60 || (rtpe_now.tv_sec - s->outbuf->active) >= 60) control_stream_closed(s); } diff --git a/daemon/cookie_cache.c b/daemon/cookie_cache.c index 8f5b2052d..bbcf7c552 100644 --- a/daemon/cookie_cache.c +++ b/daemon/cookie_cache.c @@ -18,19 +18,19 @@ INLINE void cookie_cache_state_init(struct cookie_cache_state *s) { void cookie_cache_init(struct cookie_cache *c) { cookie_cache_state_init(&c->current); cookie_cache_state_init(&c->old); - c->swap_time = poller_now; + c->swap_time = rtpe_now.tv_sec; mutex_init(&c->lock); cond_init(&c->cond); } /* lock must be held */ static void __cookie_cache_check_swap(struct cookie_cache *c) { - if (poller_now - c->swap_time >= 30) { + if (rtpe_now.tv_sec - c->swap_time >= 30) { g_hash_table_remove_all(c->old.cookies); g_string_chunk_clear(c->old.chunks); swap_ptrs(&c->old.chunks, &c->current.chunks); swap_ptrs(&c->old.cookies, &c->current.cookies); - c->swap_time = poller_now; + c->swap_time = rtpe_now.tv_sec; } } diff --git a/daemon/dtls.c b/daemon/dtls.c index 9943901e7..3915b39fe 100644 --- a/daemon/dtls.c +++ b/daemon/dtls.c @@ -317,7 +317,7 @@ static void __dtls_timer(void *p) { long int left; c = dtls_cert(); - left = c->expires - poller_now; + left = c->expires - rtpe_now.tv_sec; if (left > CERT_EXPIRY_TIME/2) goto out; diff --git a/daemon/graphite.c b/daemon/graphite.c index d634fa831..8502eec6c 100644 --- a/daemon/graphite.c +++ b/daemon/graphite.c @@ -25,7 +25,7 @@ static socket_t graphite_sock; static int connection_state = STATE_DISCONNECTED; //struct totalstats totalstats_prev; static time_t next_run; -// HEAD: static time_t g_now, next_run; +// HEAD: static time_t rtpe_now, next_run; static char* graphite_prefix = NULL; static struct timeval graphite_interval_tv; static struct totalstats graphite_stats; @@ -149,69 +149,69 @@ int send_graphite_data(struct callmaster *cm, struct totalstats *sent_data) { timeval_divide(&ts->delete.time_avg, &ts->delete.time_avg, ts->delete.count); if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } - rc = sprintf(ptr,"offer_time_min %llu.%06llu %llu\n",(unsigned long long)ts->offer.time_min.tv_sec,(unsigned long long)ts->offer.time_min.tv_usec,(unsigned long long)g_now.tv_sec); ptr += rc; + rc = sprintf(ptr,"offer_time_min %llu.%06llu %llu\n",(unsigned long long)ts->offer.time_min.tv_sec,(unsigned long long)ts->offer.time_min.tv_usec,(unsigned long long)rtpe_now.tv_sec); ptr += rc; if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } - rc = sprintf(ptr,"offer_time_max %llu.%06llu %llu\n",(unsigned long long)ts->offer.time_max.tv_sec,(unsigned long long)ts->offer.time_max.tv_usec,(unsigned long long)g_now.tv_sec); ptr += rc; + rc = sprintf(ptr,"offer_time_max %llu.%06llu %llu\n",(unsigned long long)ts->offer.time_max.tv_sec,(unsigned long long)ts->offer.time_max.tv_usec,(unsigned long long)rtpe_now.tv_sec); ptr += rc; if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } - rc = sprintf(ptr,"offer_time_avg %llu.%06llu %llu\n",(unsigned long long)ts->offer.time_avg.tv_sec,(unsigned long long)ts->offer.time_avg.tv_usec,(unsigned long long)g_now.tv_sec); ptr += rc; + rc = sprintf(ptr,"offer_time_avg %llu.%06llu %llu\n",(unsigned long long)ts->offer.time_avg.tv_sec,(unsigned long long)ts->offer.time_avg.tv_usec,(unsigned long long)rtpe_now.tv_sec); ptr += rc; if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } - rc = sprintf(ptr,"answer_time_min %llu.%06llu %llu\n",(unsigned long long)ts->answer.time_min.tv_sec,(unsigned long long)ts->answer.time_min.tv_usec,(unsigned long long)g_now.tv_sec); ptr += rc; + rc = sprintf(ptr,"answer_time_min %llu.%06llu %llu\n",(unsigned long long)ts->answer.time_min.tv_sec,(unsigned long long)ts->answer.time_min.tv_usec,(unsigned long long)rtpe_now.tv_sec); ptr += rc; if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } - rc = sprintf(ptr,"answer_time_max %llu.%06llu %llu\n",(unsigned long long)ts->answer.time_max.tv_sec,(unsigned long long)ts->answer.time_max.tv_usec,(unsigned long long)g_now.tv_sec); ptr += rc; + rc = sprintf(ptr,"answer_time_max %llu.%06llu %llu\n",(unsigned long long)ts->answer.time_max.tv_sec,(unsigned long long)ts->answer.time_max.tv_usec,(unsigned long long)rtpe_now.tv_sec); ptr += rc; if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } - rc = sprintf(ptr,"answer_time_avg %llu.%06llu %llu\n",(unsigned long long)ts->answer.time_avg.tv_sec,(unsigned long long)ts->answer.time_avg.tv_usec,(unsigned long long)g_now.tv_sec); ptr += rc; + rc = sprintf(ptr,"answer_time_avg %llu.%06llu %llu\n",(unsigned long long)ts->answer.time_avg.tv_sec,(unsigned long long)ts->answer.time_avg.tv_usec,(unsigned long long)rtpe_now.tv_sec); ptr += rc; if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } - rc = sprintf(ptr,"delete_time_min %llu.%06llu %llu\n",(unsigned long long)ts->delete.time_min.tv_sec,(unsigned long long)ts->delete.time_min.tv_usec,(unsigned long long)g_now.tv_sec); ptr += rc; + rc = sprintf(ptr,"delete_time_min %llu.%06llu %llu\n",(unsigned long long)ts->delete.time_min.tv_sec,(unsigned long long)ts->delete.time_min.tv_usec,(unsigned long long)rtpe_now.tv_sec); ptr += rc; if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } - rc = sprintf(ptr,"delete_time_max %llu.%06llu %llu\n",(unsigned long long)ts->delete.time_max.tv_sec,(unsigned long long)ts->delete.time_max.tv_usec,(unsigned long long)g_now.tv_sec); ptr += rc; + rc = sprintf(ptr,"delete_time_max %llu.%06llu %llu\n",(unsigned long long)ts->delete.time_max.tv_sec,(unsigned long long)ts->delete.time_max.tv_usec,(unsigned long long)rtpe_now.tv_sec); ptr += rc; if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } - rc = sprintf(ptr,"delete_time_avg %llu.%06llu %llu\n",(unsigned long long)ts->delete.time_avg.tv_sec,(unsigned long long)ts->delete.time_avg.tv_usec,(unsigned long long)g_now.tv_sec); ptr += rc; + rc = sprintf(ptr,"delete_time_avg %llu.%06llu %llu\n",(unsigned long long)ts->delete.time_avg.tv_sec,(unsigned long long)ts->delete.time_avg.tv_usec,(unsigned long long)rtpe_now.tv_sec); ptr += rc; if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } - rc = sprintf(ptr, "call_dur %llu.%06llu %llu\n",(unsigned long long)ts->total_calls_duration_interval.tv_sec,(unsigned long long)ts->total_calls_duration_interval.tv_usec,(unsigned long long)g_now.tv_sec); ptr += rc; + rc = sprintf(ptr, "call_dur %llu.%06llu %llu\n",(unsigned long long)ts->total_calls_duration_interval.tv_sec,(unsigned long long)ts->total_calls_duration_interval.tv_usec,(unsigned long long)rtpe_now.tv_sec); ptr += rc; if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } - rc = sprintf(ptr,"average_call_dur %llu.%06llu %llu\n",(unsigned long long)ts->total_average_call_dur.tv_sec,(unsigned long long)ts->total_average_call_dur.tv_usec,(unsigned long long)g_now.tv_sec); ptr += rc; + rc = sprintf(ptr,"average_call_dur %llu.%06llu %llu\n",(unsigned long long)ts->total_average_call_dur.tv_sec,(unsigned long long)ts->total_average_call_dur.tv_usec,(unsigned long long)rtpe_now.tv_sec); ptr += rc; if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } - rc = sprintf(ptr,"forced_term_sess "UINT64F" %llu\n", atomic64_get_na(&ts->total_forced_term_sess),(unsigned long long)g_now.tv_sec); ptr += rc; + rc = sprintf(ptr,"forced_term_sess "UINT64F" %llu\n", atomic64_get_na(&ts->total_forced_term_sess),(unsigned long long)rtpe_now.tv_sec); ptr += rc; if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } - rc = sprintf(ptr,"managed_sess "UINT64F" %llu\n", ts->total_managed_sess,(unsigned long long)g_now.tv_sec); ptr += rc; + rc = sprintf(ptr,"managed_sess "UINT64F" %llu\n", ts->total_managed_sess,(unsigned long long)rtpe_now.tv_sec); ptr += rc; if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } - rc = sprintf(ptr,"managed_sess_min "UINT64F" %llu\n", ts->managed_sess_min,(unsigned long long)g_now.tv_sec); ptr += rc; + rc = sprintf(ptr,"managed_sess_min "UINT64F" %llu\n", ts->managed_sess_min,(unsigned long long)rtpe_now.tv_sec); ptr += rc; if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } - rc = sprintf(ptr,"managed_sess_max "UINT64F" %llu\n", ts->managed_sess_max,(unsigned long long)g_now.tv_sec); ptr += rc; + rc = sprintf(ptr,"managed_sess_max "UINT64F" %llu\n", ts->managed_sess_max,(unsigned long long)rtpe_now.tv_sec); ptr += rc; if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } - rc = sprintf(ptr,"current_sessions_total "UINT64F" %llu\n", ts->total_sessions,(unsigned long long)g_now.tv_sec); ptr += rc; + rc = sprintf(ptr,"current_sessions_total "UINT64F" %llu\n", ts->total_sessions,(unsigned long long)rtpe_now.tv_sec); ptr += rc; if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } - rc = sprintf(ptr,"current_sessions_own "UINT64F" %llu\n", ts->own_sessions,(unsigned long long)g_now.tv_sec); ptr += rc; + rc = sprintf(ptr,"current_sessions_own "UINT64F" %llu\n", ts->own_sessions,(unsigned long long)rtpe_now.tv_sec); ptr += rc; if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } - rc = sprintf(ptr,"current_sessions_foreign "UINT64F" %llu\n", ts->foreign_sessions,(unsigned long long)g_now.tv_sec); ptr += rc; + rc = sprintf(ptr,"current_sessions_foreign "UINT64F" %llu\n", ts->foreign_sessions,(unsigned long long)rtpe_now.tv_sec); ptr += rc; if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } - rc = sprintf(ptr,"nopacket_relayed_sess "UINT64F" %llu\n", atomic64_get_na(&ts->total_nopacket_relayed_sess),(unsigned long long)g_now.tv_sec); ptr += rc; + rc = sprintf(ptr,"nopacket_relayed_sess "UINT64F" %llu\n", atomic64_get_na(&ts->total_nopacket_relayed_sess),(unsigned long long)rtpe_now.tv_sec); ptr += rc; if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } - rc = sprintf(ptr,"oneway_stream_sess "UINT64F" %llu\n", atomic64_get_na(&ts->total_oneway_stream_sess),(unsigned long long)g_now.tv_sec); ptr += rc; + rc = sprintf(ptr,"oneway_stream_sess "UINT64F" %llu\n", atomic64_get_na(&ts->total_oneway_stream_sess),(unsigned long long)rtpe_now.tv_sec); ptr += rc; if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } - rc = sprintf(ptr,"regular_term_sess "UINT64F" %llu\n", atomic64_get_na(&ts->total_regular_term_sess),(unsigned long long)g_now.tv_sec); ptr += rc; + rc = sprintf(ptr,"regular_term_sess "UINT64F" %llu\n", atomic64_get_na(&ts->total_regular_term_sess),(unsigned long long)rtpe_now.tv_sec); ptr += rc; if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } - rc = sprintf(ptr,"relayed_errors "UINT64F" %llu\n", atomic64_get_na(&ts->total_relayed_errors),(unsigned long long)g_now.tv_sec); ptr += rc; + rc = sprintf(ptr,"relayed_errors "UINT64F" %llu\n", atomic64_get_na(&ts->total_relayed_errors),(unsigned long long)rtpe_now.tv_sec); ptr += rc; if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } - rc = sprintf(ptr,"relayed_packets "UINT64F" %llu\n", atomic64_get_na(&ts->total_relayed_packets),(unsigned long long)g_now.tv_sec); ptr += rc; + rc = sprintf(ptr,"relayed_packets "UINT64F" %llu\n", atomic64_get_na(&ts->total_relayed_packets),(unsigned long long)rtpe_now.tv_sec); ptr += rc; if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } - rc = sprintf(ptr,"silent_timeout_sess "UINT64F" %llu\n", atomic64_get_na(&ts->total_silent_timeout_sess),(unsigned long long)g_now.tv_sec); ptr += rc; + rc = sprintf(ptr,"silent_timeout_sess "UINT64F" %llu\n", atomic64_get_na(&ts->total_silent_timeout_sess),(unsigned long long)rtpe_now.tv_sec); ptr += rc; if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } - rc = sprintf(ptr,"final_timeout_sess "UINT64F" %llu\n", atomic64_get_na(&ts->total_final_timeout_sess),(unsigned long long)g_now.tv_sec); ptr += rc; + rc = sprintf(ptr,"final_timeout_sess "UINT64F" %llu\n", atomic64_get_na(&ts->total_final_timeout_sess),(unsigned long long)rtpe_now.tv_sec); ptr += rc; if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } - rc = sprintf(ptr,"timeout_sess "UINT64F" %llu\n", atomic64_get_na(&ts->total_timeout_sess),(unsigned long long)g_now.tv_sec); ptr += rc; + rc = sprintf(ptr,"timeout_sess "UINT64F" %llu\n", atomic64_get_na(&ts->total_timeout_sess),(unsigned long long)rtpe_now.tv_sec); ptr += rc; if (graphite_prefix!=NULL) { rc = sprintf(ptr,"%s",graphite_prefix); ptr += rc; } - rc = sprintf(ptr,"reject_sess "UINT64F" %llu\n", atomic64_get_na(&ts->total_rejected_sess),(unsigned long long)g_now.tv_sec); ptr += rc; + rc = sprintf(ptr,"reject_sess "UINT64F" %llu\n", atomic64_get_na(&ts->total_rejected_sess),(unsigned long long)rtpe_now.tv_sec); ptr += rc; ilog(LOG_DEBUG, "min_sessions:%llu max_sessions:%llu, call_dur_per_interval:%llu.%06llu at time %llu\n", (unsigned long long) ts->managed_sess_min, (unsigned long long) ts->managed_sess_max, (unsigned long long ) ts->total_calls_duration_interval.tv_sec, (unsigned long long ) ts->total_calls_duration_interval.tv_usec, - (unsigned long long ) g_now.tv_sec); + (unsigned long long ) rtpe_now.tv_sec); ilog(LOG_DEBUG, "Min/Max/Avg offer processing delay: %llu.%06llu/%llu.%06llu/%llu.%06llu sec", (unsigned long long)ts->offer.time_min.tv_sec,(unsigned long long)ts->offer.time_min.tv_usec, @@ -294,13 +294,13 @@ void graphite_loop_run(struct callmaster *cm, endpoint_t *graphite_ep, int secon } } - gettimeofday(&g_now, NULL); - if (g_now.tv_sec < next_run) { + gettimeofday(&rtpe_now, NULL); + if (rtpe_now.tv_sec < next_run) { usleep(100000); return; } - next_run = g_now.tv_sec + seconds; + next_run = rtpe_now.tv_sec + seconds; if (graphite_sock.fd < 0 && connection_state == STATE_DISCONNECTED) { connect_to_graphite_server(graphite_ep); @@ -338,6 +338,6 @@ void graphite_loop(void *d) { connect_to_graphite_server(&cm->conf.graphite_ep); - while (!g_shutdown) + while (!rtpe_shutdown) graphite_loop_run(cm, &cm->conf.graphite_ep, cm->conf.graphite_interval); // time in seconds } diff --git a/daemon/ice.c b/daemon/ice.c index 7b9171138..7238f562e 100644 --- a/daemon/ice.c +++ b/daemon/ice.c @@ -240,7 +240,7 @@ static void __ice_agent_initialize(struct ice_agent *ag) { create_random_ice_string(call, &ag->ufrag[1], 8); create_random_ice_string(call, &ag->pwd[1], 26); - atomic64_set(&ag->last_activity, poller_now); + atomic64_set(&ag->last_activity, rtpe_now.tv_sec); } static struct ice_agent *__ice_agent_new(struct call_media *media) { @@ -315,7 +315,7 @@ void ice_update(struct ice_agent *ag, struct stream_params *sp) { if (!ag) return; - atomic64_set(&ag->last_activity, poller_now); + atomic64_set(&ag->last_activity, rtpe_now.tv_sec); media = ag->media; call = media->call; @@ -519,7 +519,7 @@ static void __ice_agent_free(void *p) { static void __agent_schedule(struct ice_agent *ag, unsigned long usec) { struct timeval nxt; - nxt = g_now; + nxt = rtpe_now; timeval_add_usec(&nxt, usec); __agent_schedule_abs(ag, &nxt); } @@ -622,7 +622,7 @@ static void __do_ice_check(struct ice_candidate_pair *pair) { mutex_lock(&ag->lock); - pair->retransmit = g_now; + pair->retransmit = rtpe_now; if (!PAIR_SET(pair, IN_PROGRESS)) { PAIR_CLEAR2(pair, FROZEN, FAILED); pair->retransmit_ms = STUN_RETRANSMIT_INTERVAL; @@ -721,7 +721,7 @@ static void __do_ice_checks(struct ice_agent *ag) { if (!ag->pwd[0].s) return; - atomic64_set(&ag->last_activity, poller_now); + atomic64_set(&ag->last_activity, rtpe_now.tv_sec); __DBG("running checks, call "STR_FORMAT" tag "STR_FORMAT"", STR_FMT(&ag->call->callid), STR_FMT(&ag->media->monologue->tag)); @@ -730,7 +730,7 @@ static void __do_ice_checks(struct ice_agent *ag) { /* check if we're done and should start nominating pairs */ if (AGENT_ISSET(ag, CONTROLLING) && !AGENT_ISSET(ag, NOMINATING) && ag->start_nominating.tv_sec) { - if (timeval_cmp(&g_now, &ag->start_nominating) >= 0) + if (timeval_cmp(&rtpe_now, &ag->start_nominating) >= 0) __nominate_pairs(ag); timeval_lowest(&next_run, &ag->start_nominating); } @@ -739,7 +739,7 @@ static void __do_ice_checks(struct ice_agent *ag) { pair = g_queue_pop_head(&ag->triggered); if (pair) { PAIR_CLEAR(pair, TRIGGERED); - next_run = g_now; + next_run = rtpe_now; goto check; } @@ -764,7 +764,7 @@ static void __do_ice_checks(struct ice_agent *ag) { if (valid && valid->pair_priority > pair->pair_priority) continue; - if (timeval_cmp(&pair->retransmit, &g_now) <= 0) + if (timeval_cmp(&pair->retransmit, &rtpe_now) <= 0) g_queue_push_tail(&retransmits, pair); /* can't run check directly due to locks */ else @@ -1090,7 +1090,7 @@ int ice_request(struct stream_fd *sfd, const endpoint_t *src, if (!ag) return -1; - atomic64_set(&ag->last_activity, poller_now); + atomic64_set(&ag->last_activity, rtpe_now.tv_sec); /* determine candidate pair */ mutex_lock(&ag->lock); @@ -1198,7 +1198,7 @@ int ice_response(struct stream_fd *sfd, const endpoint_t *src, if (!ag) return -1; - atomic64_set(&ag->last_activity, poller_now); + atomic64_set(&ag->last_activity, rtpe_now.tv_sec); mutex_lock(&ag->lock); @@ -1261,7 +1261,7 @@ int ice_response(struct stream_fd *sfd, const endpoint_t *src, if (!ag->start_nominating.tv_sec) { if (__check_succeeded_complete(ag)) { - ag->start_nominating = g_now; + ag->start_nominating = rtpe_now; timeval_add_usec(&ag->start_nominating, 100000); __agent_schedule_abs(ag, &ag->start_nominating); } @@ -1323,8 +1323,8 @@ void ice_thread_run(void *p) { mutex_lock(&ice_agents_timers_lock); - while (!g_shutdown) { - gettimeofday(&g_now, NULL); + while (!rtpe_shutdown) { + gettimeofday(&rtpe_now, NULL); /* lock our list and get the first element */ ag = g_tree_find_first(ice_agents_timers, NULL, NULL); @@ -1332,12 +1332,12 @@ void ice_thread_run(void *p) { * steal the reference and run it */ if (!ag) goto sleep; - if (timeval_cmp(&g_now, &ag->next_check) < 0) + if (timeval_cmp(&rtpe_now, &ag->next_check) < 0) goto sleep; g_tree_remove(ice_agents_timers, ag); ZERO(ag->next_check); - ag->last_run = g_now; + ag->last_run = rtpe_now; mutex_unlock(&ice_agents_timers_lock); /* this agent is scheduled to run right now */ @@ -1359,9 +1359,9 @@ void ice_thread_run(void *p) { sleep: /* figure out how long we should sleep */ - sleeptime = ag ? timeval_diff(&ag->next_check, &g_now) : 100000; + sleeptime = ag ? timeval_diff(&ag->next_check, &rtpe_now) : 100000; sleeptime = MIN(100000, sleeptime); /* 100 ms at the most */ - tv = g_now; + tv = rtpe_now; timeval_add_usec(&tv, sleeptime); cond_timedwait(&ice_agents_timers_cond, &ice_agents_timers_lock, &tv); continue; diff --git a/daemon/iptables.c b/daemon/iptables.c index 84981113f..7a81e5476 100644 --- a/daemon/iptables.c +++ b/daemon/iptables.c @@ -1,6 +1,6 @@ #include "iptables.h" -char *g_iptables_chain; +char *rtpe_iptables_chain; int (*iptables_add_rule)(const socket_t *local_sock, const str *comment); int (*iptables_del_rule)(const socket_t *local_sock); @@ -139,7 +139,7 @@ static const char *ip4tables_add_rule(const socket_t *local_sock, const str *com ip4_fill_entry(&entry, local_sock, comment); err = "failed to append iptables entry"; - if (!iptc_append_entry(g_iptables_chain, &entry.entry, h)) + if (!iptc_append_entry(rtpe_iptables_chain, &entry.entry, h)) goto err; err = "failed to commit iptables changes"; if (!iptc_commit(h)) @@ -169,7 +169,7 @@ static const char *ip6tables_add_rule(const socket_t *local_sock, const str *com ip6_fill_entry(&entry, local_sock, comment); err = "failed to append ip6tables entry"; - if (!ip6tc_append_entry(g_iptables_chain, &entry.entry, h)) + if (!ip6tc_append_entry(rtpe_iptables_chain, &entry.entry, h)) goto err; err = "failed to commit ip6tables changes"; if (!ip6tc_commit(h)) @@ -207,7 +207,7 @@ static const char *ip4tables_del_rule(const socket_t *local_sock) { memset(&mask.matches.target, 0xff, sizeof(mask.matches.target)); err = "failed to delete iptables entry"; - if (!iptc_delete_entry(g_iptables_chain, &entry.entry, (unsigned char *) &mask, h)) + if (!iptc_delete_entry(rtpe_iptables_chain, &entry.entry, (unsigned char *) &mask, h)) goto err; err = "failed to commit iptables changes"; if (!iptc_commit(h)) @@ -245,7 +245,7 @@ static const char *ip6tables_del_rule(const socket_t *local_sock) { memset(&mask.matches.target, 0xff, sizeof(mask.matches.target)); err = "failed to delete ip6tables entry"; - if (!ip6tc_delete_entry(g_iptables_chain, &entry.entry, (unsigned char *) &mask, h)) + if (!ip6tc_delete_entry(rtpe_iptables_chain, &entry.entry, (unsigned char *) &mask, h)) goto err; err = "failed to commit ip6tables changes"; if (!ip6tc_commit(h)) @@ -313,10 +313,10 @@ static int __iptables_stub(void) { void iptables_init(void) { - if (g_iptables_chain && !g_iptables_chain[0]) - g_iptables_chain = NULL; + if (rtpe_iptables_chain && !rtpe_iptables_chain[0]) + rtpe_iptables_chain = NULL; - if (!g_iptables_chain) { + if (!rtpe_iptables_chain) { iptables_add_rule = (void *) __iptables_stub; iptables_del_rule = (void *) __iptables_stub; return; @@ -340,7 +340,7 @@ void iptables_init(void) { if (!h) goto out; err = "could not flush iptables chain"; - if (!iptc_flush_entries(g_iptables_chain, h)) + if (!iptc_flush_entries(rtpe_iptables_chain, h)) goto err2; err = "could not commit iptables changes"; if (!iptc_commit(h)) @@ -352,7 +352,7 @@ void iptables_init(void) { if (!h) goto out; err = "could not flush ip6tables chain"; - if (!ip6tc_flush_entries(g_iptables_chain, h)) + if (!ip6tc_flush_entries(rtpe_iptables_chain, h)) goto err1; err = "could not commit iptables changes"; if (!ip6tc_commit(h)) diff --git a/daemon/iptables.h b/daemon/iptables.h index 77f988550..96cd24e26 100644 --- a/daemon/iptables.h +++ b/daemon/iptables.h @@ -6,7 +6,7 @@ #include "str.h" -extern char *g_iptables_chain; +extern char *rtpe_iptables_chain; void iptables_init(void); extern int (*iptables_add_rule)(const socket_t *local_sock, const str *comment); diff --git a/daemon/main.c b/daemon/main.c index ac27cd25b..73e1729d9 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -97,7 +97,7 @@ static void sighandler(gpointer x) { ts.tv_sec = 0; ts.tv_nsec = 100000000; /* 0.1 sec */ - while (!g_shutdown) { + while (!rtpe_shutdown) { ret = sigtimedwait(&ss, NULL, &ts); if (ret == -1) { if (errno == EAGAIN || errno == EINTR) @@ -106,7 +106,7 @@ static void sighandler(gpointer x) { } if (ret == SIGINT || ret == SIGTERM) - g_shutdown = 1; + rtpe_shutdown = 1; else if (ret == SIGUSR1) { if (get_log_level() > 0) { g_atomic_int_add(&log_level, -1); @@ -300,7 +300,7 @@ static void options(int *argc, char ***argv) { { "recording-method",0, 0, G_OPTION_ARG_STRING, &rec_method, "Strategy for call recording", "pcap|proc" }, { "recording-format",0, 0, G_OPTION_ARG_STRING, &rec_format, "File format for stored pcap files", "raw|eth" }, #ifdef WITH_IPTABLES_OPTION - { "iptables-chain",0,0, G_OPTION_ARG_STRING, &g_iptables_chain,"Add explicit firewall rules to this iptables chain","STRING" }, + { "iptables-chain",0,0, G_OPTION_ARG_STRING, &rtpe_iptables_chain,"Add explicit firewall rules to this iptables chain","STRING" }, #endif { NULL, } }; @@ -674,7 +674,7 @@ int main(int argc, char **argv) { thread_create_detach(poller_loop, ctx.p); } - while (!g_shutdown) { + while (!rtpe_shutdown) { usleep(100000); threads_join_all(0); } diff --git a/daemon/media_socket.c b/daemon/media_socket.c index b9381ab52..4582e13cc 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -1435,7 +1435,7 @@ loop_ok: /* wait at least 3 seconds after last signal before committing to a particular * endpoint address */ - if (!call->last_signal || poller_now <= call->last_signal + 3) + if (!call->last_signal || rtpe_now.tv_sec <= call->last_signal + 3) goto update_peerinfo; ilog(LOG_INFO, "Confirmed peer address as %s", endpoint_print_buf(fsin)); @@ -1522,7 +1522,7 @@ drop: ret = 0; atomic64_inc(&stream->stats.packets); atomic64_add(&stream->stats.bytes, s->len); - atomic64_set(&stream->last_packet, poller_now); + atomic64_set(&stream->last_packet, rtpe_now.tv_sec); atomic64_inc(&cm->statsps.packets); atomic64_add(&cm->statsps.bytes, s->len); diff --git a/daemon/poller.c b/daemon/poller.c index 9382acf91..ccdbf7a9f 100644 --- a/daemon/poller.c +++ b/daemon/poller.c @@ -55,7 +55,7 @@ struct poller *poller_new(void) { p = malloc(sizeof(*p)); memset(p, 0, sizeof(*p)); - gettimeofday(&g_now, NULL); + gettimeofday(&rtpe_now, NULL); p->fd = epoll_create1(0); if (p->fd == -1) abort(); @@ -311,7 +311,7 @@ int poller_poll(struct poller *p, int timeout) { if (ret <= 0) goto out; - gettimeofday(&g_now, NULL); + gettimeofday(&rtpe_now, NULL); for (i = 0; i < ret; i++) { ev = &evs[i]; @@ -482,9 +482,9 @@ void poller_timer_loop(void *d) { struct timeval tv; int wt; - while (!g_shutdown) { + while (!rtpe_shutdown) { gettimeofday(&tv, NULL); - if (tv.tv_sec != poller_now) + if (tv.tv_sec != rtpe_now.tv_sec) goto now; wt = 1000000 - tv.tv_usec; @@ -493,7 +493,7 @@ void poller_timer_loop(void *d) { continue; now: - gettimeofday(&g_now, NULL); + gettimeofday(&rtpe_now, NULL); poller_timers_run(p); } } @@ -501,6 +501,6 @@ now: void poller_loop(void *d) { struct poller *p = d; - while (!g_shutdown) + while (!rtpe_shutdown) poller_poll(p, 100); } diff --git a/daemon/poller.h b/daemon/poller.h index 41a29e751..8ede2f343 100644 --- a/daemon/poller.h +++ b/daemon/poller.h @@ -30,10 +30,6 @@ struct poller_item { struct poller; -/* XXX replace all occurrences with g_now */ -#define poller_now g_now.tv_sec - - struct poller *poller_new(void); int poller_add_item(struct poller *, struct poller_item *); int poller_update_item(struct poller *, struct poller_item *); diff --git a/daemon/recording.c b/daemon/recording.c index 464f4a241..46b83d785 100644 --- a/daemon/recording.c +++ b/daemon/recording.c @@ -373,7 +373,7 @@ static int pcap_meta_finish_file(struct call *call) { // Print start timestamp and end timestamp // YYYY-MM-DDThh:mm:ss time_t start = call->created.tv_sec; - time_t end = g_now.tv_sec; + time_t end = rtpe_now.tv_sec; char timebuffer[20]; struct tm *timeinfo; timeinfo = localtime(&start); @@ -503,7 +503,7 @@ static void stream_pcap_dump(pcap_dumper_t *pdumper, struct packet_stream *strea // Set up PCAP packet header struct pcap_pkthdr header; ZERO(header); - header.ts = g_now; + header.ts = rtpe_now; header.caplen = pkt_len; header.len = pkt_len; diff --git a/daemon/redis.c b/daemon/redis.c index 26b4ff5b7..f3c258286 100644 --- a/daemon/redis.c +++ b/daemon/redis.c @@ -560,7 +560,7 @@ static int redis_notify(struct callmaster *cm) { void redis_notify_loop(void *d) { int seconds = 1, redis_notify_return = 0; - time_t next_run = g_now.tv_sec; + time_t next_run = rtpe_now.tv_sec; struct callmaster *cm = (struct callmaster *)d; struct redis *r; @@ -598,14 +598,14 @@ void redis_notify_loop(void *d) { } // loop redis_notify => in case of lost connection - while (!g_shutdown) { - gettimeofday(&g_now, NULL); - if (g_now.tv_sec < next_run) { + while (!rtpe_shutdown) { + gettimeofday(&rtpe_now, NULL); + if (rtpe_now.tv_sec < next_run) { usleep(100000); continue; } - next_run = g_now.tv_sec + seconds; + next_run = rtpe_now.tv_sec + seconds; if (redis_check_conn(r) == REDIS_STATE_RECONNECTED || redis_notify_return < 0) { // alloc new redis async context upon redis breakdown diff --git a/daemon/statistics.c b/daemon/statistics.c index af536550c..bf4eaf173 100644 --- a/daemon/statistics.c +++ b/daemon/statistics.c @@ -180,7 +180,7 @@ void statistics_update_oneway(struct call* c) { if (c->monologues.head) { ml = c->monologues.head->data; - timeval_subtract(&tim_result_duration, &g_now, &ml->started); + timeval_subtract(&tim_result_duration, &rtpe_now, &ml->started); if (IS_OWN_CALL(c)) { if (ml->term_reason==TIMEOUT) { diff --git a/daemon/streambuf.c b/daemon/streambuf.c index c7da2dfc1..073609fbe 100644 --- a/daemon/streambuf.c +++ b/daemon/streambuf.c @@ -25,7 +25,7 @@ struct streambuf *streambuf_new(struct poller *p, int fd) { b->buf = g_string_new(""); b->fd = fd; b->poller = p; - b->active = poller_now; + b->active = rtpe_now.tv_sec; return b; } @@ -62,7 +62,7 @@ int streambuf_writeable(struct streambuf *b) { if (ret > 0) { g_string_erase(b->buf, 0, ret); - b->active = poller_now; + b->active = rtpe_now.tv_sec; } if (ret != out) { @@ -101,7 +101,7 @@ int streambuf_readable(struct streambuf *b) { } g_string_append_len(b->buf, buf, ret); - b->active = poller_now; + b->active = rtpe_now.tv_sec; } mutex_unlock(&b->lock); @@ -208,7 +208,7 @@ void streambuf_write(struct streambuf *b, const char *s, unsigned int len) { s += ret; len -= ret; - b->active = poller_now; + b->active = rtpe_now.tv_sec; } if (b->buf->len > 5242880)