From d3c630ad8fc24020ace8ca27e779ba7ba7f837e3 Mon Sep 17 00:00:00 2001 From: tb Date: Wed, 21 Feb 2024 12:48:25 +0000 Subject: [PATCH] Group logx() getmonotime() and get_current_time() together Fix their indent in extern.h, move the X509_TIME_* macros to main.c since they aren't (and can't really be) used elsewhere, document the meaning of the magic numbers. Also move get_current_time() out of the middle of entity handlers. ok claudio job --- usr.sbin/rpki-client/extern.h | 15 ++++----------- usr.sbin/rpki-client/main.c | 27 ++++++++++++++++++--------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/usr.sbin/rpki-client/extern.h b/usr.sbin/rpki-client/extern.h index 6a6652df7c8..10235441c0b 100644 --- a/usr.sbin/rpki-client/extern.h +++ b/usr.sbin/rpki-client/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.206 2024/02/21 12:38:10 tb Exp $ */ +/* $OpenBSD: extern.h,v 1.207 2024/02/21 12:48:25 tb Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * @@ -902,9 +902,10 @@ int output_json(FILE *, struct vrp_tree *, struct brk_tree *, int output_ometric(FILE *, struct vrp_tree *, struct brk_tree *, struct vap_tree *, struct stats *); -void logx(const char *fmt, ...) +void logx(const char *fmt, ...) __attribute__((format(printf, 1, 2))); -time_t getmonotime(void); +time_t getmonotime(void); +time_t get_current_time(void); int mkpath(const char *); int mkpathat(int, const char *); @@ -956,12 +957,4 @@ int mkpathat(int, const char *); /* Maximum number of delegated hosting locations (repositories) for each TAL. */ #define MAX_REPO_PER_TAL 1000 -/* - * Time - Evaluation time is used as the current time if it is - * larger than X509_TIME_MIN, otherwise the system time is used. - */ -#define X509_TIME_MAX 253402300799LL -#define X509_TIME_MIN -62167219200LL -extern time_t get_current_time(void); - #endif /* ! EXTERN_H */ diff --git a/usr.sbin/rpki-client/main.c b/usr.sbin/rpki-client/main.c index 67eea26e45b..6f51e0fac75 100644 --- a/usr.sbin/rpki-client/main.c +++ b/usr.sbin/rpki-client/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.249 2024/02/16 11:55:42 tb Exp $ */ +/* $OpenBSD: main.c,v 1.250 2024/02/21 12:48:25 tb Exp $ */ /* * Copyright (c) 2021 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -74,6 +74,11 @@ int rrdpon = 1; int repo_timeout; time_t deadline; +/* 9999-12-31 23:59:59 UTC */ +#define X509_TIME_MAX 253402300799LL +/* 0000-01-01 00:00:00 UTC */ +#define X509_TIME_MIN -62167219200LL + int64_t evaluation_time = X509_TIME_MIN; struct stats stats; @@ -113,6 +118,18 @@ getmonotime(void) return (ts.tv_sec); } +/* + * Time - Evaluation time is used as the current time if it is + * larger than X509_TIME_MIN, otherwise the system time is used. + */ +time_t +get_current_time(void) +{ + if (evaluation_time > X509_TIME_MIN) + return (time_t)evaluation_time; + return time(NULL); +} + void entity_free(struct entity *ent) { @@ -126,14 +143,6 @@ entity_free(struct entity *ent) free(ent); } -time_t -get_current_time(void) -{ - if (evaluation_time > X509_TIME_MIN) - return (time_t)evaluation_time; - return time(NULL); -} - /* * Read a queue entity from the descriptor. * Matched by entity_write_req(). -- 2.20.1