Error reformatting, and use the suspend-aware monotonic clock on Linux.

This commit is contained in:
Adam Ierymenko 2021-04-13 18:57:44 -04:00
parent 37d706b635
commit ad92a46b8d
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
8 changed files with 73 additions and 77 deletions

View file

@ -19,10 +19,11 @@
namespace ZeroTier {
/**
* A per-API-call equivalent to the runtime
* A per-API-call equivalent to the general context.
*
* This captures several things that are passed into API calls and follow
* the call chain. Some such as tPtr may be supplied to callbacks.
* This is created when external C API calls are made and follows the call
* graph around from function to function as needed. It's cleaner and probably
* faster than passing clock, ticks, and tPtr around everywhere.
*/
class CallContext
{

View file

@ -18,8 +18,10 @@
#include <sys/stat.h>
#ifndef __WINDOWS__
#include <dirent.h>
#include <fcntl.h>
#endif
#include <algorithm>
@ -32,20 +34,24 @@
namespace ZeroTier {
#ifdef __APPLE__
static clock_serv_t _machGetRealtimeClock() noexcept
{
clock_serv_t c;
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &c);
return c;
}
static clock_serv_t _machGetMonotonicClock() noexcept
{
clock_serv_t c;
host_get_clock_service(mach_host_self(),REALTIME_CLOCK,&c);
host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &c);
return c;
}
clock_serv_t OSUtils::s_machRealtimeClock = _machGetRealtimeClock();
clock_serv_t OSUtils::s_machMonotonicClock = _machGetMonotonicClock();
#endif
unsigned int OSUtils::ztsnprintf(char *buf, unsigned int len, const char *fmt, ...)
@ -66,6 +72,7 @@ unsigned int OSUtils::ztsnprintf(char *buf,unsigned int len,const char *fmt,...)
}
#ifdef __UNIX_LIKE__
bool OSUtils::redirectUnixOutputs(const char *stdoutPath, const char *stderrPath)
{
int fdout = open(stdoutPath, O_WRONLY | O_CREAT, 0600);
@ -86,6 +93,7 @@ bool OSUtils::redirectUnixOutputs(const char *stdoutPath,const char *stderrPath)
}
return false;
}
#endif // __UNIX_LIKE__
Vector< String > OSUtils::listDirectory(const char *path, bool includeDirectories)

View file

@ -196,11 +196,7 @@ public:
#else
#ifdef __LINUX__
timespec ts;
#ifdef CLOCK_MONOTONIC_COARSE
clock_gettime(CLOCK_MONOTONIC_COARSE,&ts);
#else
clock_gettime(CLOCK_MONOTONIC,&ts);
#endif
clock_gettime(CLOCK_BOOTTIME,&ts);
return ( (1000LL * (int64_t)ts.tv_sec) + ((int64_t)(ts.tv_nsec / 1000000)) );
#else
#ifdef __APPLE__

View file

@ -807,6 +807,6 @@ mod tests {
let cert_signed_decoded = cert_signed_decoded.ok().unwrap();
assert!(cert_signed_decoded.signature.len() > 0);
assert!(cert_signed_decoded.verify() == CertificateError::None);
assert!(cert_signed_decoded.verify(-1) == CertificateError::None);
}
}

View file

@ -274,7 +274,7 @@ fn delete<'a>(store: &Arc<Store>, cli_args: &ArgMatches<'a>) -> i32 {
0
}
pub(crate) fn run<'a>(store: Arc<Store>, cli_args: &ArgMatches<'a>) -> i32 {
pub(crate) fn run(store: Arc<Store>, cli_args: &ArgMatches) -> i32 {
match cli_args.subcommand() {
("list", None) => list(&store),
("show", Some(sub_cli_args)) => show(&store, sub_cli_args),

View file

@ -35,17 +35,9 @@ use crate::osdep as osdep;
#[cfg(unix)]
fn bind_udp_socket(_device_name: &str, address: &InetAddress) -> Result<FastUDPRawOsSocket, &'static str> {
unsafe {
let af;
let sa_len;
match address.family() {
InetAddressFamily::IPv4 => {
af = osdep::AF_INET;
sa_len = std::mem::size_of::<osdep::sockaddr_in>() as osdep::socklen_t;
}
InetAddressFamily::IPv6 => {
af = osdep::AF_INET6;
sa_len = std::mem::size_of::<osdep::sockaddr_in6>() as osdep::socklen_t;
}
let (af, sa_len) = match address.family() {
InetAddressFamily::IPv4 => (osdep::AF_INET, std::mem::size_of::<osdep::sockaddr_in>() as osdep::socklen_t),
InetAddressFamily::IPv6 => (osdep::AF_INET6, std::mem::size_of::<osdep::sockaddr_in6>() as osdep::socklen_t),
_ => {
return Err("unrecognized address family");
}

View file

@ -18,7 +18,6 @@ use zerotier_core::InetAddress;
use crate::osdep as osdep;
#[inline(always)]
fn s6_addr_as_ptr<A>(a: &A) -> *const A {
a as *const A
}

View file

@ -47,9 +47,9 @@ impl Error for UnexpectedStatusCodeError {}
impl std::fmt::Display for UnexpectedStatusCodeError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
if self.1.is_empty() {
write!(f, "unexpected status code: {} {}", self.0.as_str(), self.0.canonical_reason().unwrap_or("???"))
write!(f, "{} {} (???)", self.0.as_str(), self.0.canonical_reason().unwrap_or("???"))
} else {
write!(f, "unexpected status code: {} {} ({})", self.0.as_str(), self.0.canonical_reason().unwrap_or("???"), self.1)
write!(f, "{} {} ({})", self.0.as_str(), self.0.canonical_reason().unwrap_or("???"), self.1)
}
}
}