]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Everybody hates gettimeofday(), Season 1
authorJorge Pereira <jpereiran@gmail.com>
Sat, 18 May 2019 01:00:21 +0000 (22:00 -0300)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 18 May 2019 05:36:05 +0000 (01:36 -0400)
src/bin/unit_test_module.c
src/lib/server/main_loop.c
src/lib/server/stats.c
src/lib/server/xlat_eval.c
src/modules/rlm_date/rlm_date.c

index d3b57eee2b3c39bbc56e6a2eb44a6a00b3c52878..ffa08c315e8cb688f4114de0986df6837a781620 100644 (file)
@@ -460,13 +460,11 @@ static bool do_xlats(char const *filename, FILE *fp)
        char            input[8192];
        char            output[8192];
        REQUEST         *request;
-       struct timeval  now;
 
        /*
         *      Create and initialize the new request.
         */
        request = request_alloc(NULL);
-       gettimeofday(&now, NULL);
 
        request->log.dst = talloc_zero(request, log_dst_t);
        request->log.dst->func = vlog_request;
index e7c34d11a127222b9578c628f8759b59e9e32a46..41f00e36b1c386a78d24001a3941ec89616ccb26 100644 (file)
@@ -255,9 +255,7 @@ int main_loop_init(void)
 
 #ifdef HAVE_SYSTEMD_WATCHDOG
        if (sd_watchdog_interval.tv_sec || sd_watchdog_interval.tv_usec) {
-               struct timeval  now;
-               fr_time_to_timeval(&now, fr_event_list_time(event_list));
-               sd_watchdog_event(event_list, &now, NULL);
+               sd_watchdog_event(event_list, 0, NULL);
        }
 #endif
 
index b6fa3614597dbb3d3fc8ae11256632568cff8a89..56e45899cc2ca16b9405854020fd1a86b1d2d925 100644 (file)
@@ -36,8 +36,8 @@ RCSID("$Id$")
 #define EMA_SCALE (100)
 #define F_EMA_SCALE (1000000)
 
-static struct timeval  start_time;
-static struct timeval  hup_time;
+static fr_time_t start_time;
+static fr_time_t hup_time;
 
 #define FR_STATS_INIT { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      \
                                 { 0, 0, 0, 0, 0, 0, 0, 0 }}
@@ -552,9 +552,9 @@ void request_stats_reply(REQUEST *request)
         */
        if ((flag->vp_uint32 & 0x10) != 0) {
                vp = ADD_TO_REPLY(FR_FREERADIUS_STATS_START_TIME, VENDORPEC_FREERADIUS);
-               if (vp) vp->vp_date = start_time.tv_sec;
+               if (vp) vp->vp_date = fr_time_to_sec(start_time);
                vp = ADD_TO_REPLY(FR_FREERADIUS_STATS_HUP_TIME, VENDORPEC_FREERADIUS);
-               if (vp) vp->vp_date = hup_time.tv_sec;
+               if (vp) vp->vp_date = fr_time_to_sec(hup_time);
        }
 
        /*
@@ -800,10 +800,10 @@ void request_stats_reply(REQUEST *request)
 void radius_stats_init(int flag)
 {
        if (!flag) {
-               gettimeofday(&start_time, NULL);
+               start_time = fr_time();
                hup_time = start_time; /* it's just nicer this way */
        } else {
-               gettimeofday(&hup_time, NULL);
+               hup_time = fr_time();
        }
 }
 
index 7d711d8747b6bb5fac813c126d3beafd345d313c..45cda32a779dede6102f0e15cecce9b292194496 100644 (file)
@@ -284,25 +284,15 @@ static xlat_action_t xlat_eval_one_letter(TALLOC_CTX *ctx, fr_cursor_t *out, REQ
         */
 
        case 'c': /* Current epoch time seconds */
-       {
-               struct timeval now;
-
-               gettimeofday(&now, NULL);
-
                MEM(value = fr_value_box_alloc(ctx, FR_TYPE_UINT64, NULL, false));
-               value->datum.uint64 = (uint64_t)now.tv_sec;
-       }
+               value->datum.uint64 = (uint64_t)fr_time_to_sec(fr_time());
+
                break;
 
        case 'C': /* Current epoch time microsecond component */
-       {
-               struct timeval now;
-
-               gettimeofday(&now, NULL);
+               MEM(value = fr_value_box_alloc(ctx, FR_TYPE_UINT64, NULL, false));
+               value->datum.uint64 = (uint64_t)fr_time_to_usec(fr_time());
 
-               MEM(value = fr_value_box_alloc(ctx, FR_TYPE_UINT32, NULL, false));
-               value->datum.uint32 = (uint64_t)now.tv_usec;
-       }
                break;
 
        /*
index bdb01a1f13107c86ca350816747fb66cc195fb86..4259593ed63bbc709290a2c31f77a50b44fb8303 100644 (file)
@@ -89,7 +89,6 @@ static ssize_t xlat_date_convert(UNUSED TALLOC_CTX *ctx, char **out, size_t outl
 {
        rlm_date_t const *inst = mod_inst;
        struct tm tminfo;
-       struct timeval now;
        VALUE_PAIR *vp;
 
        memset(&tminfo, 0, sizeof(tminfo));
@@ -100,8 +99,7 @@ static ssize_t xlat_date_convert(UNUSED TALLOC_CTX *ctx, char **out, size_t outl
        }
 
        if (strcmp(fmt, "now") == 0) {
-               gettimeofday(&now, NULL);
-               return date_encode_strftime(out, outlen, inst, request, now.tv_sec);
+               return date_encode_strftime(out, outlen, inst, request, fr_time_to_sec(fr_time()));
        }
 
        if ((xlat_fmt_get_vp(&vp, request, fmt) < 0) || !vp) return 0;