From 792ce25af93bbd1f65632e31ce93b6ea08a3b80e Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Sun, 3 May 2020 20:24:03 +0000 Subject: Use strftime() rather than ctime() to generate timestamps nicer. ok job, input claudio benno --- usr.sbin/rpki-client/output-json.c | 10 ++++++---- usr.sbin/rpki-client/output.c | 12 +++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/rpki-client/output-json.c b/usr.sbin/rpki-client/output-json.c index 3fb69fdf9fb..452b7672bb0 100644 --- a/usr.sbin/rpki-client/output-json.c +++ b/usr.sbin/rpki-client/output-json.c @@ -1,4 +1,4 @@ -/* $OpenBSD: output-json.c,v 1.11 2020/05/03 19:41:54 deraadt Exp $ */ +/* $OpenBSD: output-json.c,v 1.12 2020/05/03 20:24:02 deraadt Exp $ */ /* * Copyright (c) 2019 Claudio Jeker * @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -26,19 +27,20 @@ static int outputheader_json(FILE *out, struct stats *st) { char hn[NI_MAXHOST], tbuf[26]; + struct tm *tp; time_t t; time(&t); setenv("TZ", "UTC", 1); - ctime_r(&t, tbuf); - *strrchr(tbuf, '\n') = '\0'; + tp = localtime(&t); + strftime(tbuf, sizeof tbuf, "%FT%TZ", tp); gethostname(hn, sizeof hn); if (fprintf(out, "{\n\t\"metadata\": {\n" "\t\t\"buildmachine\": \"%s\",\n" - "\t\t\"buildtime\": \"%s UTC\",\n" + "\t\t\"buildtime\": \"%s\",\n" "\t\t\"elapsedtime\": \"%lld\",\n" "\t\t\"usertime\": \"%lld\",\n" "\t\t\"systemtime\": \"%lld\",\n" diff --git a/usr.sbin/rpki-client/output.c b/usr.sbin/rpki-client/output.c index ef544fccb81..442664a9b70 100644 --- a/usr.sbin/rpki-client/output.c +++ b/usr.sbin/rpki-client/output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: output.c,v 1.14 2020/05/03 19:41:54 deraadt Exp $ */ +/* $OpenBSD: output.c,v 1.15 2020/05/03 20:24:02 deraadt Exp $ */ /* * Copyright (c) 2019 Theo de Raadt * @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -173,18 +174,19 @@ set_signal_handler(void) int outputheader(FILE *out, struct stats *st) { - char hn[NI_MAXHOST], tbuf[26]; + char hn[NI_MAXHOST], tbuf[80]; + struct tm *tp; time_t t; time(&t); setenv("TZ", "UTC", 1); - ctime_r(&t, tbuf); - *strrchr(tbuf, '\n') = '\0'; + tp = localtime(&t); + strftime(tbuf, sizeof tbuf, "%a %b %e %H:%M:%S %Z %Y", tp); gethostname(hn, sizeof hn); if (fprintf(out, - "# Generated on host %s at %s UTC\n" + "# Generated on host %s at %s\n" "# Processing time %lld seconds (%lld seconds user, %lld seconds system)\n" "# Route Origin Authorizations: %zu (%zu failed parse, %zu invalid)\n" "# Certificates: %zu (%zu failed parse, %zu invalid)\n" -- cgit v1.2.3