Skip to content

Commit

Permalink
Use CLOCK_REALTIME when logging and CLOCK_MONOTONIC when timing under…
Browse files Browse the repository at this point in the history
… Free- and OpenBSD and macOS
  • Loading branch information
gsnw committed Dec 20, 2023
1 parent a3f4c57 commit b00622c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
23 changes: 16 additions & 7 deletions src/fping.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,26 @@ extern int h_errno;

/*** Constants ***/

/* CLOCK_MONTONIC starts under macOS, OpenBSD and FreeBSD with undefined positive point and can not be use
* see github PR #217
* The configure script detect the predefined operating systems an set CLOCK_REALTIME using over ONLY_CLOCK_REALTIME variable
*/
#if HAVE_SO_TIMESTAMPNS || ONLY_CLOCK_REALTIME
#if HAVE_SO_TIMESTAMPNS
#define CLOCKID CLOCK_REALTIME
#define CLOCK_CURRENT_TIME CLOCK_REALTIME
#endif

#if !defined(CLOCKID)
#if defined(CLOCK_MONOTONIC)
#define CLOCKID CLOCK_MONOTONIC
/* CLOCK_MONTONIC starts under macOS, OpenBSD and FreeBSD with undefined positive point and can not be use
* see github PR #217
* The configure script detect the predefined operating systems an set CLOCK_REALTIME using over ONLY_CLOCK_REALTIME variable
*/
#if ONLY_CLOCK_REALTIME
#define CLOCK_CURRENT_TIME CLOCK_REALTIME
#else
#define CLOCK_CURRENT_TIME CLOCK_MONOTONIC
#endif
#else
#define CLOCKID CLOCK_REALTIME
#define CLOCK_CURRENT_TIME CLOCK_REALTIME
#endif
#endif

Expand Down Expand Up @@ -1510,8 +1517,10 @@ void signal_handler(int signum)

void update_current_time()
{
clock_gettime(CLOCKID, &current_time);
current_time_ns = timespec_ns(&current_time);
clock_gettime(CLOCK_CURRENT_TIME, &current_time);
struct timespec current_time_clockid;
clock_gettime(CLOCKID, &current_time_clockid);
current_time_ns = timespec_ns(&current_time_clockid);
}

/************************************************************
Expand Down
6 changes: 3 additions & 3 deletions src/seqmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ unsigned int seqmap_add(unsigned int host_nr, unsigned int ping_count, int64_t t
/* check if expired (note that unused seqmap values will have fields set to
* 0, so will be seen as expired */
next_value = &seqmap_map[seqmap_next_id];
if (timestamp - next_value->ping_ts < SEQMAP_TIMEOUT_IN_NS) {
fprintf(stderr, "fping error: not enough sequence numbers available! (expire_timeout=%" PRId64 ", host_nr=%d, ping_count=%d, seqmap_next_id=%d)\n",
SEQMAP_TIMEOUT_IN_NS, host_nr, ping_count, seqmap_next_id);
if (next_value->ping_ts != 0 && timestamp - next_value->ping_ts < SEQMAP_TIMEOUT_IN_NS) {
fprintf(stderr, "fping error: not enough sequence numbers available! (expire_timeout=%" PRId64 ", host_nr=%d, ping_count=%d, seqmap_next_id=%d ping_st=%" PRId64 ")\n",
SEQMAP_TIMEOUT_IN_NS, host_nr, ping_count, seqmap_next_id, next_value->ping_ts);
exit(4);
}

Expand Down

0 comments on commit b00622c

Please sign in to comment.