major refactor
* uccm add parsers and metrics for gps sats, loop diag * cleanups and improvements * fix refclock to survive chrony restart * cargo updates * etc
This commit is contained in:
@@ -2,15 +2,14 @@ use async_trait::async_trait;
|
||||
use chimemon::{ChimemonMessage, ChimemonTarget, ChimemonTargetChannel, ChronySockConfig};
|
||||
use libc::{c_double, c_int, timeval};
|
||||
use log::debug;
|
||||
use std::io::prelude::*;
|
||||
use std::mem;
|
||||
use std::os::unix::net::UnixDatagram;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
const CHRONY_MAGIC: c_int = 0x534f434b;
|
||||
|
||||
pub struct ChronySockServer {
|
||||
sock: UnixDatagram,
|
||||
sock_path: PathBuf,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@@ -26,15 +25,9 @@ pub struct ChronyTimeReport {
|
||||
|
||||
impl ChronySockServer {
|
||||
pub fn new(config: ChronySockConfig) -> Self {
|
||||
debug!(
|
||||
"Size of chrony refclock report: {}",
|
||||
mem::size_of::<ChronyTimeReport>()
|
||||
);
|
||||
let sock = UnixDatagram::unbound().unwrap();
|
||||
// TODO: Don't connect to the socket or we break when chrony restarts
|
||||
// use sock.send_to instead and fail gracefully
|
||||
sock.connect(&config.sock).expect("Unable to open socket");
|
||||
ChronySockServer { sock }
|
||||
ChronySockServer {
|
||||
sock_path: config.sock.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,8 +42,16 @@ impl ChimemonTarget for ChronySockServer {
|
||||
{
|
||||
let frame = ChronyTimeReport {
|
||||
tv: timeval {
|
||||
tv_sec: tr.system_time.timestamp().try_into().unwrap_or_default(),
|
||||
tv_usec: tr.system_time.timestamp_subsec_micros().try_into().unwrap_or_default(),
|
||||
tv_sec: tr
|
||||
.system_time
|
||||
.timestamp()
|
||||
.try_into()
|
||||
.unwrap_or_default(),
|
||||
tv_usec: tr
|
||||
.system_time
|
||||
.timestamp()
|
||||
.try_into()
|
||||
.unwrap_or_default(),
|
||||
},
|
||||
offset: tr.offset.num_nanoseconds().unwrap() as f64 / 1e9,
|
||||
leap: if tr.leap_flag { 1 } else { 0 },
|
||||
@@ -58,14 +59,15 @@ impl ChimemonTarget for ChronySockServer {
|
||||
_pad: 0,
|
||||
magic: CHRONY_MAGIC,
|
||||
};
|
||||
unsafe {
|
||||
let bs = std::slice::from_raw_parts(
|
||||
let bs = unsafe {
|
||||
std::slice::from_raw_parts(
|
||||
(&frame as *const ChronyTimeReport) as *const u8,
|
||||
mem::size_of::<ChronyTimeReport>(),
|
||||
);
|
||||
debug!("Sending to chrony sock {:#?}", frame);
|
||||
self.sock.send(bs).unwrap();
|
||||
)
|
||||
};
|
||||
debug!("Sending to chrony sock {:#?}", frame);
|
||||
let sock = UnixDatagram::unbound().unwrap();
|
||||
sock.send_to(bs, &self.sock_path).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user