From: Petr Špaček Date: Tue, 22 Oct 2019 11:26:04 +0000 (+0200) Subject: doh debug: log timestamp of OPENSSLKEYLOGFILE creation X-Git-Tag: v4.3.0~8^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1803e1bd5f066792b933d7dda67f0fdcba728f39;p=thirdparty%2Fknot-resolver.git doh debug: log timestamp of OPENSSLKEYLOGFILE creation --- diff --git a/modules/http/debug_opensslkeylog.c b/modules/http/debug_opensslkeylog.c index 9677c9512..5e97e2f7a 100644 --- a/modules/http/debug_opensslkeylog.c +++ b/modules/http/debug_opensslkeylog.c @@ -47,9 +47,6 @@ # define OPENSSL_SONAME "libssl.so" #endif -#define FIRSTLINE "# SSL key logfile generated by sslkeylog.c\n" -#define FIRSTLINE_LEN (sizeof(FIRSTLINE) - 1) - /* When building for OpenSSL 1.1.0 or newer, no headers are required. */ #ifdef NO_OPENSSL_102_SUPPORT typedef struct ssl_st SSL; @@ -112,10 +109,14 @@ static void init_keylog_file(void) const char *filename = getenv("OPENSSLKEYLOGFILE"); if (filename) { - keylog_file_fd = open(filename, O_WRONLY | O_APPEND | O_CREAT, 0644); + /* ctime output is max 26 bytes, POSIX 1003.1-2017 */ + keylog_file_fd = open(filename, O_WRONLY | O_APPEND | O_CREAT, 0644); if (keylog_file_fd >= 0 && lseek(keylog_file_fd, 0, SEEK_END) == 0) { + time_t timenow = time(NULL); + char txtnow[30] = { '#', ' ', 0 }; + ctime_r(&timenow, txtnow + 2); /* file is opened successfully and there is no data (pos == 0) */ - write(keylog_file_fd, FIRSTLINE, FIRSTLINE_LEN); + write(keylog_file_fd, txtnow, strlen(txtnow)); } } }