summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Habets <thomas@habets.se>2017-10-01 14:48:05 +0100
committerThomas Habets <thomas@habets.se>2017-10-01 14:48:05 +0100
commita897635a10e0b75e44a15b216dcf5e5aae923b2b (patch)
treea84193fa6086c8caa8cf7b03dc3565a13eba23c1
parentf9d4f225735596a544962d09b62d9e6218bb143a (diff)
downloadarping-a897635a10e0b75e44a15b216dcf5e5aae923b2b.tar.gz
Fall back to gettimeofday() if clock_gettime() fails
-rw-r--r--src/arping.c14
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
}
/**