]> arthur.barton.de Git - netdata.git/commitdiff
`replace `time(NULL)` calls by `now_realtime_sec()`
authorRémi Lefèvre <remi.lefevre@parrot.com>
Thu, 8 Dec 2016 21:22:48 +0000 (22:22 +0100)
committerRémi Lefèvre <remi.lefevre@parrot.com>
Sun, 11 Dec 2016 10:51:57 +0000 (11:51 +0100)
Signed-off-by: Rémi Lefèvre <remi.lefevre@parrot.com>
13 files changed:
src/apps_plugin.c
src/eval.c
src/health.c
src/log.c
src/plugin_nfacct.c
src/plugins_d.c
src/proc_diskstats.c
src/registry.c
src/rrd.c
src/rrd2json.c
src/sys_fs_cgroup.c
src/unit_test.c
src/web_client.c

index c126791d4c6a3afdd8b8f7e6e534c8152ed9673a..26811656c91e19832b358571f5ed6393891d0969 100644 (file)
@@ -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();
@@ -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);
index a4450f92c7c586d9e57353f6d32c40b900d5d3ff..122959ce4edb06d6ea99999838e53ec320d1046a 100644 (file)
@@ -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, " ] ");
index 27dcc8075825cf660a23c00960696af82462d1dc..c14c29d8737d122d207371e9a3c21ce0ee5ef872 100755 (executable)
@@ -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;
@@ -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;
@@ -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);
     }
 }
@@ -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);
     }
 
@@ -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) {
@@ -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);
@@ -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);
 
@@ -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;
 
@@ -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));
index dc00834236bf982dac79a5232614fa36260a5505..78c58ab80302110a12f26bbcc225df8118eaca9a 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -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) {
@@ -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;
index 7843161d32bf86e3bce565cf742e2dd3bfbfce97..b258005ba05440ec70c12e49a81a7d82a8e2155a 100644 (file)
@@ -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) {
index 4053653233bb0f181e5723075999e1c8227a5b57..e7197c30617cf859793a076d41f06594f27a2820 100644 (file)
@@ -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));
index e6004ecd84eef51bab1871bb11e5b1094df0b2e7..26ac061f1063d139d7df233a351a1ac1d9829577 100644 (file)
@@ -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
index bce7c348fa0339933f98c20070fb8f1890eb5d8c..b47bdd225f6c6de6b4c587a73013d6c80630648d 100644 (file)
@@ -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);
 
index 52de637bccf97c1b0bdd16a744ed4db030ccbf34..1a2d307d39a2fd87747735e842145a320fdc39f0 100644 (file)
--- a/src/rrd.c
+++ b/src/rrd.c
@@ -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) {
@@ -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);
index d4a200fec7747363fe8aeae59679fe555450d461..c7a46982bb83437cee3cb3ee31a2e7f86bb3050f 100644 (file)
@@ -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);
 
index cef7cb449c2bcb93c1edcffd4581622e374cb647..cef5c721434afdb352602508812ca8859d08b02e 100644 (file)
@@ -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();
@@ -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;
 
index 139e99755bdf036a95569a507f39ef24a9fc416b..3c99b3e84b79f9155e0844282109aebf0990b4af 100644 (file)
@@ -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++) {
index 024533df112e1fce27e984b187ed4261c135a0c2..b36af6332085d08eefa03949bba99edd49fe0d4c 100644 (file)
@@ -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);
 
@@ -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,
@@ -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);
 
@@ -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);