n-acd: use CLOCK_MONOTONIC timers on older kernels

The README states that a kernel >= 3.0 is enough, however
CLOCK_BOOTTIME is only available since kernel 3.15.

Fall back to CLOCK_MONOTONIC when CLOCK_BOOTTIME is not available.

See: https://github.com/nettools/n-acd/pull/3

Signed-off-by: Beniamino Galvani <bgalvani@redhat.com>
This commit is contained in:
Beniamino Galvani 2018-04-17 21:35:32 +02:00
parent 8a01bdc2d1
commit 8c3023d471

View file

@ -264,6 +264,13 @@ _public_ int n_acd_new(NAcd **acdp) {
}
acd->fd_timer = timerfd_create(CLOCK_BOOTTIME, TFD_CLOEXEC | TFD_NONBLOCK);
if (acd->fd_timer < 0 && errno == EINVAL) {
/*
* Fall back to CLOCK_MONOTONIC when CLOCK_BOOTTIME is
* not available (kernel < 3.15).
*/
acd->fd_timer = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
}
if (acd->fd_timer < 0) {
r = -n_acd_errno();
goto error;