From: Jonathan McDowell Date: Sat, 2 Jan 2021 11:18:55 +0000 (+0000) Subject: Switch to re-entrant versions of *time functions X-Git-Tag: onak-0.6.2~9 X-Git-Url: https://the.earth.li/gitweb/?a=commitdiff_plain;h=97be85bfba76b9ed0aa6ad01afc7c6efc4b370d5;p=onak.git Switch to re-entrant versions of *time functions We're not running these in a multi-threaded scenario at present, but it makes sense to avoid them. --- diff --git a/keydb/keydctl.c b/keydb/keydctl.c index 8712f63..7a659ab 100644 --- a/keydb/keydctl.c +++ b/keydb/keydctl.c @@ -150,6 +150,7 @@ static void keyd_status(void) { uint32_t reply; struct keyd_stats stats; + char started[26]; /* ctime(3) says 26 is the necessary size */ if (keyd_do_command(KEYD_CMD_VERSION, &reply, sizeof(reply)) == -1) { printf("Got failure asking for keyd version.\n"); @@ -162,7 +163,7 @@ static void keyd_status(void) return; } - printf("keyd running since %s", ctime(&stats.started)); + printf("keyd running since %s", ctime_r(&stats.started, started)); printf("%d client connections received\n", stats.connects); printf("Command statistics:\n"); diff --git a/keyindex.c b/keyindex.c index eeac56c..e8d569a 100644 --- a/keyindex.c +++ b/keyindex.c @@ -231,7 +231,7 @@ int list_subkeys(struct onak_dbctx *dbctx, struct openpgp_signedpacket_list *subkeys, bool verbose, bool html) { - struct tm *created = NULL; + struct tm created; time_t created_time = 0; int type = 0; int length = 0; @@ -244,7 +244,7 @@ int list_subkeys(struct onak_dbctx *dbctx, (subkeys->packet->data[2] << 16) + (subkeys->packet->data[3] << 8) + subkeys->packet->data[4]; - created = gmtime(&created_time); + gmtime_r(&created_time, &created); switch (subkeys->packet->data[0]) { case 2: @@ -270,9 +270,9 @@ int list_subkeys(struct onak_dbctx *dbctx, length, pkalgo2char(type), keyid, - created->tm_year + 1900, - created->tm_mon + 1, - created->tm_mday); + created.tm_year + 1900, + created.tm_mon + 1, + created.tm_mday); } if (verbose) { @@ -348,13 +348,14 @@ int key_index(struct onak_dbctx *dbctx, bool skshash, bool html) { struct openpgp_signedpacket_list *curuid = NULL; - struct tm *created = NULL; + struct tm created; time_t created_time = 0; int type = 0; int length = 0; char buf[1024]; uint64_t keyid; + if (html) { puts("
");
 	}
@@ -364,7 +365,7 @@ int key_index(struct onak_dbctx *dbctx,
 					(keys->publickey->data[2] << 16) +
 					(keys->publickey->data[3] << 8) +
 					keys->publickey->data[4];
-		created = gmtime(&created_time);
+		gmtime_r(&created_time, &created);
 
 		switch (keys->publickey->data[0]) {
 		case 2:
@@ -393,17 +394,17 @@ int key_index(struct onak_dbctx *dbctx,
 				pkalgo2char(type),
 				keyid,
 				keyid,
-				created->tm_year + 1900,
-				created->tm_mon + 1,
-				created->tm_mday);
+				created.tm_year + 1900,
+				created.tm_mon + 1,
+				created.tm_mday);
 		} else {
 			printf("pub  %5d%c/0x%016" PRIX64 " %04d/%02d/%02d ",
 				length,
 				pkalgo2char(type),
 				keyid,
-				created->tm_year + 1900,
-				created->tm_mon + 1,
-				created->tm_mday);
+				created.tm_year + 1900,
+				created.tm_mon + 1,
+				created.tm_mday);
 		}
 
 		curuid = keys->uids;
diff --git a/log.c b/log.c
index 45ec17e..7c6f2ee 100644
--- a/log.c
+++ b/log.c
@@ -133,19 +133,19 @@ loglevels getlogthreshold(void)
  */
 static void vflog(FILE *logfile, const char *format, va_list ap)
 {
-	struct tm *timestamp = NULL;
-	time_t     timer = 0;
+	struct tm timestamp;
+	time_t    timer = 0;
 
 	timer = time(NULL);
-	timestamp = localtime(&timer);
+	localtime_r(&timer, ×tamp);
 
 	fprintf(logfile, "[%02d/%02d/%4d %02d:%02d:%02d] %s[%d]: ",
-			timestamp->tm_mday,
-			timestamp->tm_mon + 1,
-			timestamp->tm_year + 1900,
-			timestamp->tm_hour,
-			timestamp->tm_min,
-			timestamp->tm_sec,
+			timestamp.tm_mday,
+			timestamp.tm_mon + 1,
+			timestamp.tm_year + 1900,
+			timestamp.tm_hour,
+			timestamp.tm_min,
+			timestamp.tm_sec,
 			(logappname == NULL) ? "" : logappname,
 			getpid());
 	vfprintf(logfile, format, ap);