Skip to content

Commit

Permalink
replace time(NULL) calls by now_realtime_sec()`
Browse files Browse the repository at this point in the history
Signed-off-by: Rémi Lefèvre <remi.lefevre@parrot.com>
  • Loading branch information
rlefevre committed Dec 11, 2016
1 parent ff9312b commit 6a65ef0
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/apps_plugin.c
Expand Up @@ -2798,7 +2798,7 @@ int main(int argc, char **argv)

procfile_adaptive_initial_allocation = 1;

time_t started_t = time(NULL);
time_t started_t = now_realtime_sec();
get_system_HZ();
get_system_pid_max();
get_system_cpus();
Expand Down Expand Up @@ -2890,7 +2890,7 @@ int main(int argc, char **argv)
if(unlikely(debug))
fprintf(stderr, "apps.plugin: done Loop No %llu\n", global_iterations_counter);

time_t current_t = time(NULL);
time_t current_t = now_realtime_sec();

// restart check (14400 seconds)
if(current_t - started_t > 14400) exit(0);
Expand Down
2 changes: 1 addition & 1 deletion src/eval.c
Expand Up @@ -102,7 +102,7 @@ static inline calculated_number eval_variable(EVAL_EXPRESSION *exp, EVAL_VARIABL
}

if(unlikely(v->hash == now_hash && !strcmp(v->name, "now"))) {
n = time(NULL);
n = now_realtime_sec();
buffer_strcat(exp->error_msg, "[ $now = ");
print_parsed_as_constant(exp->error_msg, n);
buffer_strcat(exp->error_msg, " ] ");
Expand Down
20 changes: 10 additions & 10 deletions src/health.c
Expand Up @@ -314,8 +314,8 @@ static inline ssize_t health_alarm_log_read(RRDHOST *host, FILE *fp, const char

freez(buf);

if(!max_unique_id) max_unique_id = (uint32_t)time(NULL);
if(!max_alarm_id) max_alarm_id = (uint32_t)time(NULL);
if(!max_unique_id) max_unique_id = (uint32_t)now_realtime_sec();
if(!max_alarm_id) max_alarm_id = (uint32_t)now_realtime_sec();

host->health_log.next_log_id = max_unique_id + 1;
host->health_log.next_alarm_id = max_alarm_id + 1;
Expand Down Expand Up @@ -1053,7 +1053,7 @@ static inline const char *rrdcalc_status2string(int status) {
static void rrdsetcalc_link(RRDSET *st, RRDCALC *rc) {
debug(D_HEALTH, "Health linking alarm '%s.%s' to chart '%s' of host '%s'", rc->chart?rc->chart:"NOCHART", rc->name, st->id, st->rrdhost->hostname);

rc->last_status_change = time(NULL);
rc->last_status_change = now_realtime_sec();
rc->rrdset = st;

rc->rrdset_next = st->alarms;
Expand Down Expand Up @@ -1092,7 +1092,7 @@ static void rrdsetcalc_link(RRDSET *st, RRDCALC *rc) {
if(!rc->units) rc->units = strdupz(st->units);

{
time_t now = time(NULL);
time_t now = now_realtime_sec();
health_alarm_log(st->rrdhost, rc->id, rc->next_event_id++, now, rc->name, rc->rrdset->id, rc->rrdset->family, rc->exec, rc->recipient, now - rc->last_status_change, rc->old_value, rc->value, rc->status, RRDCALC_STATUS_UNINITIALIZED, rc->source, rc->units, rc->info, 0);
}
}
Expand Down Expand Up @@ -1130,7 +1130,7 @@ inline void rrdsetcalc_unlink(RRDCALC *rc) {
}

{
time_t now = time(NULL);
time_t now = now_realtime_sec();
health_alarm_log(st->rrdhost, rc->id, rc->next_event_id++, now, rc->name, rc->rrdset->id, rc->rrdset->family, rc->exec, rc->recipient, now - rc->last_status_change, rc->old_value, rc->value, rc->status, RRDCALC_STATUS_REMOVED, rc->source, rc->units, rc->info, 0);
}

Expand Down Expand Up @@ -2492,7 +2492,7 @@ void health_alarms2json(RRDHOST *host, BUFFER *wb, int all) {
host->hostname,
(host->health_log.next_log_id > 0)?(host->health_log.next_log_id - 1):0,
health_enabled?"true":"false",
(unsigned long)time(NULL));
(unsigned long)now_realtime_sec());

RRDCALC *rc;
for(i = 0, rc = host->alarms; rc ; rc = rc->next) {
Expand Down Expand Up @@ -2652,7 +2652,7 @@ static inline void health_alarm_execute(RRDHOST *host, ALARM_ENTRY *ae) {
);

ae->flags |= HEALTH_ENTRY_FLAG_EXEC_RUN;
ae->exec_run_timestamp = time(NULL);
ae->exec_run_timestamp = now_realtime_sec();

debug(D_HEALTH, "executing command '%s'", command_to_run);
FILE *fp = mypopen(command_to_run, &command_pid);
Expand Down Expand Up @@ -2688,7 +2688,7 @@ static inline void health_process_notifications(RRDHOST *host, ALARM_ENTRY *ae)
static inline void health_alarm_log_process(RRDHOST *host) {
static uint32_t stop_at_id = 0;
uint32_t first_waiting = (host->health_log.alarms)?host->health_log.alarms->unique_id:0;
time_t now = time(NULL);
time_t now = now_realtime_sec();

pthread_rwlock_rdlock(&host->health_log.alarm_log_rwlock);

Expand Down Expand Up @@ -2825,7 +2825,7 @@ void *health_main(void *ptr) {
debug(D_HEALTH, "Health monitoring iteration no %u started", loop);

int oldstate, runnable = 0;
time_t now = time(NULL);
time_t now = now_realtime_sec();
time_t next_run = now + min_run_every;
RRDCALC *rc;

Expand Down Expand Up @@ -3097,7 +3097,7 @@ void *health_main(void *ptr) {
if(unlikely(netdata_exit))
break;

now = time(NULL);
now = now_realtime_sec();
if(now < next_run) {
debug(D_HEALTH, "Health monitoring iteration no %u done. Next iteration in %d secs",
loop, (int) (next_run - now));
Expand Down
4 changes: 2 additions & 2 deletions src/log.c
Expand Up @@ -131,7 +131,7 @@ int error_log_limit(int reset) {
return 1;
#endif

time_t now = time(NULL);
time_t now = now_realtime_sec();
if(!start) start = now;

if(reset) {
Expand Down Expand Up @@ -212,7 +212,7 @@ void log_date(FILE *out)
time_t t;
struct tm *tmp, tmbuf;

t = time(NULL);
t = now_realtime_sec();
tmp = localtime_r(&t, &tmbuf);

if (tmp == NULL) return;
Expand Down
2 changes: 1 addition & 1 deletion src/plugin_nfacct.c
Expand Up @@ -70,7 +70,7 @@ void *nfacct_main(void *ptr) {
struct nlmsghdr *nlh = NULL;
unsigned int seq = 0, portid = 0;

seq = time(NULL) - 1;
seq = now_realtime_sec() - 1;

nl = mnl_socket_open(NETLINK_NETFILTER);
if(!nl) {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins_d.c
Expand Up @@ -509,7 +509,7 @@ void *pluginsd_main(void *ptr) {

cd->enabled = enabled;
cd->update_every = (int) config_get_number(cd->id, "update every", rrd_update_every);
cd->started_t = time(NULL);
cd->started_t = now_realtime_sec();

char *def = "";
snprintfz(cd->cmd, PLUGINSD_CMD_MAX, "exec %s %d %s", cd->fullfilename, cd->update_every, config_get(cd->id, "command options", def));
Expand Down
2 changes: 1 addition & 1 deletion src/proc_diskstats.c
Expand Up @@ -39,7 +39,7 @@ static struct mountinfo *disk_mountinfo_root = NULL;

static inline void mountinfo_reload(int force) {
static time_t last_loaded = 0;
time_t now = time(NULL);
time_t now = now_realtime_sec();

if(force || now - last_loaded >= NETDATA_RELOAD_MOUNTINFO_EVERY) {
//#ifdef NETDATA_INTERNAL_CHECKS
Expand Down
2 changes: 1 addition & 1 deletion src/registry.c
Expand Up @@ -1010,7 +1010,7 @@ const char *registry_to_announce(void) {

void registry_set_cookie(struct web_client *w, const char *guid) {
char edate[100];
time_t et = time(NULL) + registry.persons_expiration;
time_t et = now_realtime_sec() + registry.persons_expiration;
struct tm etmbuf, *etm = gmtime_r(&et, &etmbuf);
strftime(edate, sizeof(edate), "%a, %d %b %Y %H:%M:%S %Z", etm);

Expand Down
4 changes: 2 additions & 2 deletions src/rrd.c
Expand Up @@ -56,7 +56,7 @@ RRDHOST localhost = {
void rrdhost_init(char *hostname) {
localhost.hostname = hostname;
localhost.health_log.next_log_id =
localhost.health_log.next_alarm_id = time(NULL);
localhost.health_log.next_alarm_id = now_realtime_sec();
}

void rrdhost_rwlock(RRDHOST *host) {
Expand Down Expand Up @@ -525,7 +525,7 @@ RRDSET *rrdset_create(const char *type, const char *id, const char *name, const
error("File %s does not have the desired update frequency. Clearing it.", fullfilename);
memset(st, 0, size);
}
else if((time(NULL) - st->last_updated.tv_sec) > update_every * entries) {
else if((now_realtime_sec() - st->last_updated.tv_sec) > update_every * entries) {
errno = 0;
error("File %s is too old. Clearing it.", fullfilename);
memset(st, 0, size);
Expand Down
2 changes: 1 addition & 1 deletion src/rrd2json.c
Expand Up @@ -127,7 +127,7 @@ void rrd_stats_api_v1_charts(BUFFER *wb)

unsigned long rrd_stats_one_json(RRDSET *st, char *options, BUFFER *wb)
{
time_t now = time(NULL);
time_t now = now_realtime_sec();

pthread_rwlock_rdlock(&st->rwlock);

Expand Down
4 changes: 2 additions & 2 deletions src/sys_fs_cgroup.c
Expand Up @@ -1396,7 +1396,7 @@ int do_sys_fs_cgroup(int update_every, unsigned long long dt) {

static int cgroup_global_config_read = 0;
static time_t last_run = 0;
time_t now = time(NULL);
time_t now = now_realtime_sec();

if(unlikely(!cgroup_global_config_read)) {
read_cgroup_plugin_configuration();
Expand Down Expand Up @@ -1436,7 +1436,7 @@ void *cgroups_main(void *ptr)
unsigned long long sutime_sys_fs_cgroup = 0ULL;

// the next time we will run - aligned properly
unsigned long long sunext = (time(NULL) - (time(NULL) % rrd_update_every) + rrd_update_every) * 1000000ULL;
unsigned long long sunext = (now_realtime_sec() - (now_realtime_sec() % rrd_update_every) + rrd_update_every) * 1000000ULL;

RRDSET *stcpu_thread = NULL;

Expand Down
2 changes: 1 addition & 1 deletion src/unit_test.c
Expand Up @@ -901,7 +901,7 @@ int run_test(struct test *test)
st->debug = 1;

// feed it with the test data
time_t time_now = 0, time_start = time(NULL);
time_t time_now = 0, time_start = now_realtime_sec();
unsigned long c;
collected_number last = 0;
for(c = 0; c < test->feed_entries; c++) {
Expand Down
14 changes: 7 additions & 7 deletions src/web_client.c
Expand Up @@ -940,7 +940,7 @@ int web_client_api_request_v1_badge(struct web_client *w, char *url) {

if (refresh > 0) {
buffer_sprintf(w->response.header, "Refresh: %d\r\n", refresh);
w->response.data->expires = time(NULL) + refresh;
w->response.data->expires = now_realtime_sec() + refresh;
}
else buffer_no_cacheable(w->response.data);

Expand Down Expand Up @@ -989,7 +989,7 @@ int web_client_api_request_v1_badge(struct web_client *w, char *url) {
ret = 500;

// if the collected value is too old, don't calculate its value
if (rrdset_last_entry_t(st) >= (time(NULL) - (st->update_every * st->gap_when_lost_iterations_above)))
if (rrdset_last_entry_t(st) >= (now_realtime_sec() - (st->update_every * st->gap_when_lost_iterations_above)))
ret = rrd2value(st,
w->response.data,
&n,
Expand All @@ -1012,7 +1012,7 @@ int web_client_api_request_v1_badge(struct web_client *w, char *url) {
}
else if (refresh > 0) {
buffer_sprintf(w->response.header, "Refresh: %d\r\n", refresh);
w->response.data->expires = time(NULL) + refresh;
w->response.data->expires = now_realtime_sec() + refresh;
}
else buffer_no_cacheable(w->response.data);

Expand Down Expand Up @@ -1404,19 +1404,19 @@ int web_client_api_request_v1_registry(struct web_client *w, char *url)
if(unlikely(cookie && person_guid[0] && !strcmp(person_guid, REGISTRY_VERIFY_COOKIES_GUID)))
person_guid[0] = '\0';

return registry_request_access_json(w, person_guid, machine_guid, machine_url, url_name, time(NULL));
return registry_request_access_json(w, person_guid, machine_guid, machine_url, url_name, now_realtime_sec());

case 'D':
w->tracking_required = 1;
return registry_request_delete_json(w, person_guid, machine_guid, machine_url, delete_url, time(NULL));
return registry_request_delete_json(w, person_guid, machine_guid, machine_url, delete_url, now_realtime_sec());

case 'S':
w->tracking_required = 1;
return registry_request_search_json(w, person_guid, machine_guid, machine_url, search_machine_guid, time(NULL));
return registry_request_search_json(w, person_guid, machine_guid, machine_url, search_machine_guid, now_realtime_sec());

case 'W':
w->tracking_required = 1;
return registry_request_switch_json(w, person_guid, machine_guid, machine_url, to_person_guid, time(NULL));
return registry_request_switch_json(w, person_guid, machine_guid, machine_url, to_person_guid, now_realtime_sec());

case 'H':
return registry_request_hello_json(w);
Expand Down

0 comments on commit 6a65ef0

Please sign in to comment.