diff --git a/src/statd/iface.c b/src/statd/iface.c index 8c5e55d45..16a6be145 100644 --- a/src/statd/iface.c +++ b/src/statd/iface.c @@ -28,6 +28,16 @@ static time_t monotonic(void) return ts.tv_sec; } +/* CLOCK_REALTIME - CLOCK_MONOTONIC in whole seconds, floored */ +static time_t clock_offset(void) +{ + struct timespec rt, mono; + + clock_gettime(CLOCK_REALTIME, &rt); + clock_gettime(CLOCK_MONOTONIC, &mono); + return rt.tv_sec - mono.tv_sec - (rt.tv_nsec < mono.tv_nsec); +} + static struct iface *iface_find(struct iface_ctx *ctx, const char *name) { struct iface *l; @@ -263,12 +273,13 @@ void iface_ctx_exit(struct iface_ctx *ctx) /* Add last-change to every interface in tree whose state changed since start */ void iface_annotate(struct iface_ctx *ctx, struct lyd_node *tree) { - time_t now = time(NULL), mono = monotonic(); struct lyd_node *iface; + time_t off; if (!tree) return; + off = clock_offset(); LY_LIST_FOR(lyd_child(tree), iface) { struct iface *l; char buf[32]; @@ -277,7 +288,7 @@ void iface_annotate(struct iface_ctx *ctx, struct lyd_node *tree) if (!l || !l->changed) continue; - format_timestamp(now - (mono - l->changed), buf, sizeof(buf)); + format_timestamp(l->changed + off, buf, sizeof(buf)); if (lyd_new_term(iface, NULL, "last-change", buf, 0, NULL)) WARN("Failed adding last-change to interface %s", l->name); } diff --git a/src/statd/python/cli_pretty/cli_pretty.py b/src/statd/python/cli_pretty/cli_pretty.py index 4fa241ade..d43a855d3 100755 --- a/src/statd/python/cli_pretty/cli_pretty.py +++ b/src/statd/python/cli_pretty/cli_pretty.py @@ -665,9 +665,7 @@ def from_yang(cls, ydate): if not ydate: return None - date, tz = ydate.split("+") - tz = tz.replace(":", "") - return cls.strptime(f"{date}+{tz}", "%Y-%m-%dT%H:%M:%S%z") + return cls.fromisoformat(ydate) class Route: def __init__(self, data, ip):