Commit 7c0e3212de for openssl.org

commit 7c0e3212de81c1ea88e1367806e8a6a28d111503
Author: Anatolii Ohorodnyk <anatolii.ohorodnyk@gmail.com>
Date:   Wed Dec 31 16:05:12 2025 +0000

    threads_pthread: make lock contention log location configurable

    Add support for OPENSSL_LOCK_CONTENTION_DIR environment variable to
    specify the directory for lock contention log files. If not set,
    logs are written to the current directory (existing behavior).

    Resolves: https://github.com/openssl/openssl/issues/27975
    Reviewed-by: Neil Horman <nhorman@openssl.org>
    Reviewed-by: Nikola Pajkovsky <nikolap@openssl.org>
    Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
    Merge-date: Fri Oct  9 19:08:15 2026
    Merged-from: https://github.com/openssl/openssl/pull/29526

diff --git a/crypto/threads_pthread.c b/crypto/threads_pthread.c
index 132479bab6..daccb5fb50 100644
--- a/crypto/threads_pthread.c
+++ b/crypto/threads_pthread.c
@@ -28,6 +28,8 @@
 #define _GNU_SOURCE
 #include <execinfo.h>
 #include <unistd.h>
+#include <limits.h>
+#include <stdlib.h>
 #endif

 #include <openssl/crypto.h>
@@ -697,12 +699,16 @@ static ossl_inline pid_t get_tid(void)
 static void *init_contention_data(void)
 {
     struct stack_traces *traces;
-    char fname_fmt[] = "lock-contention-log" FIPS_SFX ".%d.txt";
-    char fname[sizeof(fname_fmt) + sizeof(int) * 3];
+    char fname[PATH_MAX];
+    const char *log_dir;
+    const char *dir;

     traces = OPENSSL_zalloc(sizeof(struct stack_traces));

-    snprintf(fname, sizeof(fname), fname_fmt, get_tid());
+    log_dir = getenv("OPENSSL_LOCK_CONTENTION_DIR");
+    dir = (log_dir != NULL && log_dir[0] != '\0') ? log_dir : ".";
+    snprintf(fname, sizeof(fname), "%s/lock-contention-log" FIPS_SFX ".%d.txt",
+        dir, get_tid());

     traces->fd = open(fname, O_WRONLY | O_APPEND | O_CLOEXEC | O_CREAT, 0600);

diff --git a/doc/man7/openssl-env.pod b/doc/man7/openssl-env.pod
index 82e43e2a7e..a1b68f893f 100644
--- a/doc/man7/openssl-env.pod
+++ b/doc/man7/openssl-env.pod
@@ -77,6 +77,19 @@ than 1, outputs information about every processed feature.

 This variable is not considered security-sensitive.

+=item B<OPENSSL_LOCK_CONTENTION_DIR>
+
+Specifies the directory where lock contention log files are written
+when OpenSSL is built with B<-DREPORT_RWLOCK_CONTENTION> added to the
+compiler flags.
+If not set or empty, log files are written to the current working directory.
+One log file is written per thread, named
+C<lock-contention-log.E<lt>tidE<gt>.txt>
+(C<lock-contention-log-fips.E<lt>tidE<gt>.txt> in the FIPS provider),
+where I<tid> is the thread ID.
+
+This variable is not considered security-sensitive.
+
 =item B<OPENSSL_MALLOC_FAILURES>, B<OPENSSL_MALLOC_FD>, B<OPENSSL_MALLOC_SEED>

 If built with debugging, this allows memory allocation to fail.