log clock_gettime() errors; #3776
Costa Tsaousis (ktsaou) committed
Jun 1, 2018 at 10:50 UTC
4a19b02cc4ace1b55e1ddc355262545d0ea9b905
1 file changed
+10
-3
src/clocks.c
+10
-3
@@ -3,8 +3,10 @@
3
#ifndef HAVE_CLOCK_GETTIME
4
inline int clock_gettime(clockid_t clk_id, struct timespec *ts) {
5
struct timeval tv;
6
- if(unlikely(gettimeofday(&tv, NULL) == -1))
6
+ if(unlikely(gettimeofday(&tv, NULL) == -1)) {
7
+ error("gettimeofday() failed.");
8
return -1;
9
+ }
10
ts->tv_sec = tv.tv_sec;
11
ts->tv_nsec = (tv.tv_usec % USEC_PER_SEC) * NSEC_PER_USEC;
12
return 0;
@@ -13,15 +15,19 @@ inline int clock_gettime(clockid_t clk_id, struct timespec *ts) {
15
16
static inline time_t now_sec(clockid_t clk_id) {
17
struct timespec ts;
16
- if(unlikely(clock_gettime(clk_id, &ts) == -1))
18
+ if(unlikely(clock_gettime(clk_id, &ts) == -1)) {
19
+ error("clock_gettime(%d, ×pec) failed.", clk_id);
20
return 0;
21
+ }
22
return ts.tv_sec;
23
}
24
25
static inline usec_t now_usec(clockid_t clk_id) {
26
struct timespec ts;
23
- if(unlikely(clock_gettime(clk_id, &ts) == -1))
27
+ if(unlikely(clock_gettime(clk_id, &ts) == -1)) {
28
+ error("clock_gettime(%d, ×pec) failed.", clk_id);
29
return 0;
30
+ }
31
return (usec_t)ts.tv_sec * USEC_PER_SEC + (ts.tv_nsec % NSEC_PER_SEC) / NSEC_PER_USEC;
32
}
33
@@ -29,6 +35,7 @@ static inline int now_timeval(clockid_t clk_id, struct timeval *tv) {
35
struct timespec ts;
36
37
if(unlikely(clock_gettime(clk_id, &ts) == -1)) {
38
+ error("clock_gettime(%d, ×pec) failed.", clk_id);
39
tv->tv_sec = 0;
40
tv->tv_usec = 0;
41
return -1;