@cryptotaxi247 / netdata-1 / commits / 6a65ef0ad

`replace `time(NULL)` calls by `now_realtime_sec()`

Signed-off-by: Rémi Lefèvre <remi.lefevre@parrot.com>

Rémi Lefèvre committed Dec 8, 2016 at 22:22 UTC 6a65ef0ad12302dbd6ee2dff5214c5df4002094c
13 files changed +32 -32
src/apps_plugin.c
+2 -2
@@ -2798,7 +2798,7 @@ int main(int argc, char **argv)
2798
2799 procfile_adaptive_initial_allocation = 1;
2800
2801 - time_t started_t = time(NULL);
2801 + time_t started_t = now_realtime_sec();
2802 get_system_HZ();
2803 get_system_pid_max();
2804 get_system_cpus();
@@ -2890,7 +2890,7 @@ int main(int argc, char **argv)
2890 if(unlikely(debug))
2891 fprintf(stderr, "apps.plugin: done Loop No %llu\n", global_iterations_counter);
2892
2893 - time_t current_t = time(NULL);
2893 + time_t current_t = now_realtime_sec();
2894
2895 // restart check (14400 seconds)
2896 if(current_t - started_t > 14400) exit(0);
src/eval.c
+1 -1
@@ -102,7 +102,7 @@ static inline calculated_number eval_variable(EVAL_EXPRESSION *exp, EVAL_VARIABL
102 }
103
104 if(unlikely(v->hash == now_hash && !strcmp(v->name, "now"))) {
105 - n = time(NULL);
105 + n = now_realtime_sec();
106 buffer_strcat(exp->error_msg, "[ $now = ");
107 print_parsed_as_constant(exp->error_msg, n);
108 buffer_strcat(exp->error_msg, " ] ");
src/health.c
+10 -10
@@ -314,8 +314,8 @@ static inline ssize_t health_alarm_log_read(RRDHOST *host, FILE *fp, const char
314
315 freez(buf);
316
317 - if(!max_unique_id) max_unique_id = (uint32_t)time(NULL);
318 - if(!max_alarm_id) max_alarm_id = (uint32_t)time(NULL);
317 + if(!max_unique_id) max_unique_id = (uint32_t)now_realtime_sec();
318 + if(!max_alarm_id) max_alarm_id = (uint32_t)now_realtime_sec();
319
320 host->health_log.next_log_id = max_unique_id + 1;
321 host->health_log.next_alarm_id = max_alarm_id + 1;
@@ -1053,7 +1053,7 @@ static inline const char *rrdcalc_status2string(int status) {
1053 static void rrdsetcalc_link(RRDSET *st, RRDCALC *rc) {
1054 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);
1055
1056 - rc->last_status_change = time(NULL);
1056 + rc->last_status_change = now_realtime_sec();
1057 rc->rrdset = st;
1058
1059 rc->rrdset_next = st->alarms;
@@ -1092,7 +1092,7 @@ static void rrdsetcalc_link(RRDSET *st, RRDCALC *rc) {
1092 if(!rc->units) rc->units = strdupz(st->units);
1093
1094 {
1095 - time_t now = time(NULL);
1095 + time_t now = now_realtime_sec();
1096 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);
1097 }
1098 }
@@ -1130,7 +1130,7 @@ inline void rrdsetcalc_unlink(RRDCALC *rc) {
1130 }
1131
1132 {
1133 - time_t now = time(NULL);
1133 + time_t now = now_realtime_sec();
1134 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);
1135 }
1136
@@ -2492,7 +2492,7 @@ void health_alarms2json(RRDHOST *host, BUFFER *wb, int all) {
2492 host->hostname,
2493 (host->health_log.next_log_id > 0)?(host->health_log.next_log_id - 1):0,
2494 health_enabled?"true":"false",
2495 - (unsigned long)time(NULL));
2495 + (unsigned long)now_realtime_sec());
2496
2497 RRDCALC *rc;
2498 for(i = 0, rc = host->alarms; rc ; rc = rc->next) {
@@ -2652,7 +2652,7 @@ static inline void health_alarm_execute(RRDHOST *host, ALARM_ENTRY *ae) {
2652 );
2653
2654 ae->flags |= HEALTH_ENTRY_FLAG_EXEC_RUN;
2655 - ae->exec_run_timestamp = time(NULL);
2655 + ae->exec_run_timestamp = now_realtime_sec();
2656
2657 debug(D_HEALTH, "executing command '%s'", command_to_run);
2658 FILE *fp = mypopen(command_to_run, &command_pid);
@@ -2688,7 +2688,7 @@ static inline void health_process_notifications(RRDHOST *host, ALARM_ENTRY *ae)
2688 static inline void health_alarm_log_process(RRDHOST *host) {
2689 static uint32_t stop_at_id = 0;
2690 uint32_t first_waiting = (host->health_log.alarms)?host->health_log.alarms->unique_id:0;
2691 - time_t now = time(NULL);
2691 + time_t now = now_realtime_sec();
2692
2693 pthread_rwlock_rdlock(&host->health_log.alarm_log_rwlock);
2694
@@ -2825,7 +2825,7 @@ void *health_main(void *ptr) {
2825 debug(D_HEALTH, "Health monitoring iteration no %u started", loop);
2826
2827 int oldstate, runnable = 0;
2828 - time_t now = time(NULL);
2828 + time_t now = now_realtime_sec();
2829 time_t next_run = now + min_run_every;
2830 RRDCALC *rc;
2831
@@ -3097,7 +3097,7 @@ void *health_main(void *ptr) {
3097 if(unlikely(netdata_exit))
3098 break;
3099
3100 - now = time(NULL);
3100 + now = now_realtime_sec();
3101 if(now < next_run) {
3102 debug(D_HEALTH, "Health monitoring iteration no %u done. Next iteration in %d secs",
3103 loop, (int) (next_run - now));
src/log.c
+2 -2
@@ -131,7 +131,7 @@ int error_log_limit(int reset) {
131 return 1;
132 #endif
133
134 - time_t now = time(NULL);
134 + time_t now = now_realtime_sec();
135 if(!start) start = now;
136
137 if(reset) {
@@ -212,7 +212,7 @@ void log_date(FILE *out)
212 time_t t;
213 struct tm *tmp, tmbuf;
214
215 - t = time(NULL);
215 + t = now_realtime_sec();
216 tmp = localtime_r(&t, &tmbuf);
217
218 if (tmp == NULL) return;
src/plugin_nfacct.c
+1 -1
@@ -70,7 +70,7 @@ void *nfacct_main(void *ptr) {
70 struct nlmsghdr *nlh = NULL;
71 unsigned int seq = 0, portid = 0;
72
73 - seq = time(NULL) - 1;
73 + seq = now_realtime_sec() - 1;
74
75 nl = mnl_socket_open(NETLINK_NETFILTER);
76 if(!nl) {
src/plugins_d.c
+1 -1
@@ -509,7 +509,7 @@ void *pluginsd_main(void *ptr) {
509
510 cd->enabled = enabled;
511 cd->update_every = (int) config_get_number(cd->id, "update every", rrd_update_every);
512 - cd->started_t = time(NULL);
512 + cd->started_t = now_realtime_sec();
513
514 char *def = "";
515 snprintfz(cd->cmd, PLUGINSD_CMD_MAX, "exec %s %d %s", cd->fullfilename, cd->update_every, config_get(cd->id, "command options", def));
src/proc_diskstats.c
+1 -1
@@ -39,7 +39,7 @@ static struct mountinfo *disk_mountinfo_root = NULL;
39
40 static inline void mountinfo_reload(int force) {
41 static time_t last_loaded = 0;
42 - time_t now = time(NULL);
42 + time_t now = now_realtime_sec();
43
44 if(force || now - last_loaded >= NETDATA_RELOAD_MOUNTINFO_EVERY) {
45 //#ifdef NETDATA_INTERNAL_CHECKS
src/registry.c
+1 -1
@@ -1010,7 +1010,7 @@ const char *registry_to_announce(void) {
1010
1011 void registry_set_cookie(struct web_client *w, const char *guid) {
1012 char edate[100];
1013 - time_t et = time(NULL) + registry.persons_expiration;
1013 + time_t et = now_realtime_sec() + registry.persons_expiration;
1014 struct tm etmbuf, *etm = gmtime_r(&et, &etmbuf);
1015 strftime(edate, sizeof(edate), "%a, %d %b %Y %H:%M:%S %Z", etm);
1016
src/rrd.c
+2 -2
@@ -56,7 +56,7 @@ RRDHOST localhost = {
56 void rrdhost_init(char *hostname) {
57 localhost.hostname = hostname;
58 localhost.health_log.next_log_id =
59 - localhost.health_log.next_alarm_id = time(NULL);
59 + localhost.health_log.next_alarm_id = now_realtime_sec();
60 }
61
62 void rrdhost_rwlock(RRDHOST *host) {
@@ -525,7 +525,7 @@ RRDSET *rrdset_create(const char *type, const char *id, const char *name, const
525 error("File %s does not have the desired update frequency. Clearing it.", fullfilename);
526 memset(st, 0, size);
527 }
528 - else if((time(NULL) - st->last_updated.tv_sec) > update_every * entries) {
528 + else if((now_realtime_sec() - st->last_updated.tv_sec) > update_every * entries) {
529 errno = 0;
530 error("File %s is too old. Clearing it.", fullfilename);
531 memset(st, 0, size);
src/rrd2json.c
+1 -1
@@ -127,7 +127,7 @@ void rrd_stats_api_v1_charts(BUFFER *wb)
127
128 unsigned long rrd_stats_one_json(RRDSET *st, char *options, BUFFER *wb)
129 {
130 - time_t now = time(NULL);
130 + time_t now = now_realtime_sec();
131
132 pthread_rwlock_rdlock(&st->rwlock);
133
src/sys_fs_cgroup.c
+2 -2
@@ -1396,7 +1396,7 @@ int do_sys_fs_cgroup(int update_every, unsigned long long dt) {
1396
1397 static int cgroup_global_config_read = 0;
1398 static time_t last_run = 0;
1399 - time_t now = time(NULL);
1399 + time_t now = now_realtime_sec();
1400
1401 if(unlikely(!cgroup_global_config_read)) {
1402 read_cgroup_plugin_configuration();
@@ -1436,7 +1436,7 @@ void *cgroups_main(void *ptr)
1436 unsigned long long sutime_sys_fs_cgroup = 0ULL;
1437
1438 // the next time we will run - aligned properly
1439 - unsigned long long sunext = (time(NULL) - (time(NULL) % rrd_update_every) + rrd_update_every) * 1000000ULL;
1439 + unsigned long long sunext = (now_realtime_sec() - (now_realtime_sec() % rrd_update_every) + rrd_update_every) * 1000000ULL;
1440
1441 RRDSET *stcpu_thread = NULL;
1442
src/unit_test.c
+1 -1
@@ -901,7 +901,7 @@ int run_test(struct test *test)
901 st->debug = 1;
902
903 // feed it with the test data
904 - time_t time_now = 0, time_start = time(NULL);
904 + time_t time_now = 0, time_start = now_realtime_sec();
905 unsigned long c;
906 collected_number last = 0;
907 for(c = 0; c < test->feed_entries; c++) {
src/web_client.c
+7 -7
@@ -940,7 +940,7 @@ int web_client_api_request_v1_badge(struct web_client *w, char *url) {
940
941 if (refresh > 0) {
942 buffer_sprintf(w->response.header, "Refresh: %d\r\n", refresh);
943 - w->response.data->expires = time(NULL) + refresh;
943 + w->response.data->expires = now_realtime_sec() + refresh;
944 }
945 else buffer_no_cacheable(w->response.data);
946
@@ -989,7 +989,7 @@ int web_client_api_request_v1_badge(struct web_client *w, char *url) {
989 ret = 500;
990
991 // if the collected value is too old, don't calculate its value
992 - if (rrdset_last_entry_t(st) >= (time(NULL) - (st->update_every * st->gap_when_lost_iterations_above)))
992 + if (rrdset_last_entry_t(st) >= (now_realtime_sec() - (st->update_every * st->gap_when_lost_iterations_above)))
993 ret = rrd2value(st,
994 w->response.data,
995 &n,
@@ -1012,7 +1012,7 @@ int web_client_api_request_v1_badge(struct web_client *w, char *url) {
1012 }
1013 else if (refresh > 0) {
1014 buffer_sprintf(w->response.header, "Refresh: %d\r\n", refresh);
1015 - w->response.data->expires = time(NULL) + refresh;
1015 + w->response.data->expires = now_realtime_sec() + refresh;
1016 }
1017 else buffer_no_cacheable(w->response.data);
1018
@@ -1404,19 +1404,19 @@ int web_client_api_request_v1_registry(struct web_client *w, char *url)
1404 if(unlikely(cookie && person_guid[0] && !strcmp(person_guid, REGISTRY_VERIFY_COOKIES_GUID)))
1405 person_guid[0] = '\0';
1406
1407 - return registry_request_access_json(w, person_guid, machine_guid, machine_url, url_name, time(NULL));
1407 + return registry_request_access_json(w, person_guid, machine_guid, machine_url, url_name, now_realtime_sec());
1408
1409 case 'D':
1410 w->tracking_required = 1;
1411 - return registry_request_delete_json(w, person_guid, machine_guid, machine_url, delete_url, time(NULL));
1411 + return registry_request_delete_json(w, person_guid, machine_guid, machine_url, delete_url, now_realtime_sec());
1412
1413 case 'S':
1414 w->tracking_required = 1;
1415 - return registry_request_search_json(w, person_guid, machine_guid, machine_url, search_machine_guid, time(NULL));
1415 + return registry_request_search_json(w, person_guid, machine_guid, machine_url, search_machine_guid, now_realtime_sec());
1416
1417 case 'W':
1418 w->tracking_required = 1;
1419 - return registry_request_switch_json(w, person_guid, machine_guid, machine_url, to_person_guid, time(NULL));
1419 + return registry_request_switch_json(w, person_guid, machine_guid, machine_url, to_person_guid, now_realtime_sec());
1420
1421 case 'H':
1422 return registry_request_hello_json(w);