Linux: Auto-detecting clock adjustment mode

This commit is contained in:
Pavel Kirienko
2014-03-31 19:52:43 +04:00
parent fd6f27b7d8
commit 788d7348b6
2 changed files with 38 additions and 4 deletions
@@ -6,8 +6,12 @@
#include <cassert>
#include <ctime>
#include <sys/time.h>
#include <cstdint>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
#include <uavcan/driver/system_clock.hpp>
#include <uavcan_linux/exception.hpp>
@@ -56,8 +60,14 @@ class SystemClock : public uavcan::ISystemClock
return adjtime(&tv, nullptr) == 0;
}
static ClockAdjustmentMode detectPreferredClockAdjustmentMode()
{
const bool godmode = geteuid() == 0;
return godmode ? ClockAdjustmentMode::SystemWide : ClockAdjustmentMode::PerDriverPrivate;
}
public:
SystemClock(ClockAdjustmentMode adj_mode = ClockAdjustmentMode::SystemWide)
SystemClock(ClockAdjustmentMode adj_mode = detectPreferredClockAdjustmentMode())
: gradual_adj_limit_(uavcan::UtcDuration::fromMSec(4000))
, adj_mode_(adj_mode)
, step_adj_cnt_(0)