diff options
author | Thomas Habets <thomas@habets.se> | 2017-10-01 14:48:05 +0100 |
---|---|---|
committer | Thomas Habets <thomas@habets.se> | 2017-10-01 14:48:05 +0100 |
commit | a897635a10e0b75e44a15b216dcf5e5aae923b2b (patch) | |
tree | a84193fa6086c8caa8cf7b03dc3565a13eba23c1 | |
parent | f9d4f225735596a544962d09b62d9e6218bb143a (diff) | |
download | arping-a897635a10e0b75e44a15b216dcf5e5aae923b2b.tar.gz |
Fall back to gettimeofday() if clock_gettime() fails
-rw-r--r-- | src/arping.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/arping.c b/src/arping.c index 1b0b521..1ee6a4e 100644 --- a/src/arping.c +++ b/src/arping.c @@ -595,13 +595,16 @@ static void getclock(struct timespec *ts) { #if HAVE_CLOCK_MONOTONIC - if (-1 == clock_gettime(CLOCK_MONOTONIC, ts)) { - fprintf(stderr, - "arping: clock_gettime(): %s\n", + static int clock_gettime_failed = 0; + if (!clock_gettime_failed) { + if (0 == clock_gettime(CLOCK_MONOTONIC, ts)) { + return; + } + fprintf(stderr, "arping: clock_gettime(): %s\n", strerror(errno)); - sigint(0); + clock_gettime_failed = 1; // Prevent duplicate error messages. } -#else +#endif struct timeval tv; if (-1 == gettimeofday(&tv, NULL)) { fprintf(stderr, "arping: gettimeofday(): %s\n", @@ -610,7 +613,6 @@ getclock(struct timespec *ts) } ts->tv_sec = tv.tv_sec; ts->tv_nsec = tv.tv_usec * 1000; -#endif } /** |