Print thread IDs nicely.
[openssl.git] / test / testutil / init.c
index 429c1a03331118050589c8c4144082597d7014d5..7c6041aee55fc773908100227737488abf7fa2cb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2017-2019 The OpenSSL Project Authors. All Rights Reserved.
  *
  * Licensed under the Apache License 2.0 (the "License").  You may not use
  * this file except in compliance with the License.  You can obtain a copy
@@ -24,21 +24,18 @@ static size_t internal_trace_cb(const char *buf, size_t cnt,
 {
     int ret = 0;
     tracedata *trace_data = vdata;
-    union {
-        CRYPTO_THREAD_ID tid;
-        unsigned long ltid;
-    } tid;
-    char buffer[256];
+    char buffer[256], *hex;
+    CRYPTO_THREAD_ID tid;
 
     switch (cmd) {
     case OSSL_TRACE_CTRL_BEGIN:
         trace_data->ingroup = 1;
 
-        tid.ltid = 0;
-        tid.tid = CRYPTO_THREAD_get_current_id();
-
-        BIO_snprintf(buffer, sizeof(buffer), "TRACE[%lx]:%s: ", tid.ltid,
-                     OSSL_trace_get_category_name(category));
+        tid = CRYPTO_THREAD_get_current_id();
+        hex = OPENSSL_buf2hexstr((const unsigned char *)&tid, sizeof(tid));
+        BIO_snprintf(buffer, sizeof(buffer), "TRACE[%s]:%s: ",
+                     hex, OSSL_trace_get_category_name(category));
+        OPENSSL_free(hex);
         BIO_ctrl(trace_data->bio, PREFIX_CTRL_SET_PREFIX,
                  strlen(buffer), buffer);
         break;