]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Avoid mutex locking in krb5int_trace() 1375/head
authorAlexey Tikhonov <atikhono@redhat.com>
Fri, 4 Oct 2024 16:00:21 +0000 (18:00 +0200)
committerGreg Hudson <ghudson@mit.edu>
Tue, 8 Oct 2024 01:42:49 +0000 (21:42 -0400)
Trace logging doesn't need unique timestamps, so the locking within
krb5_crypto_us_timeofday() makes trace logging slower for no reason.
Add a new helper k5_us_timeofday(), which is merely a wrapper around
the existing get_time_now(), and use it in krb5int_trace().

[ghudson@mit.edu: edited commit message]

src/include/k5-int.h
src/lib/krb5/os/c_ustime.c
src/lib/krb5/os/trace.c

index 80c966ec52b5364ba333edffa8c6f0b65da35e08..863d9fe9cf98753caabcae2a7065fd15a42dbac0 100644 (file)
@@ -698,6 +698,7 @@ krb5_error_code krb5int_c_copy_keyblock_contents(krb5_context context,
                                                  const krb5_keyblock *from,
                                                  krb5_keyblock *to);
 
+krb5_error_code k5_us_timeofday(krb5_timestamp *, krb5_int32 *);
 krb5_error_code krb5_crypto_us_timeofday(krb5_timestamp *, krb5_int32 *);
 
 /*
index 7019ea1970e78c7baa16f1d5f1091985fe62d584..33559c7646bd8887a9f62959d85493c6c62ed154 100644 (file)
@@ -73,6 +73,21 @@ get_time_now(struct time_now *n)
 
 #endif
 
+krb5_error_code
+k5_us_timeofday(krb5_timestamp *seconds, krb5_int32 *microseconds)
+{
+    struct time_now now;
+    krb5_error_code err;
+
+    err = get_time_now(&now);
+    if (err)
+        return err;
+
+    *seconds = now.sec;
+    *microseconds = now.usec;
+    return 0;
+}
+
 static struct time_now last_time;
 
 krb5_error_code
index 4cbbbb270ae48623b27adf4258ec350a668ff60b..cc6d3982b0f02a0d32a492fc41e29b339de6783f 100644 (file)
@@ -411,7 +411,7 @@ krb5int_trace(krb5_context context, const char *fmt, ...)
     str = trace_format(context, fmt, ap);
     if (str == NULL)
         goto cleanup;
-    if (krb5_crypto_us_timeofday(&sec, &usec) != 0)
+    if (k5_us_timeofday(&sec, &usec) != 0)
         goto cleanup;
     if (asprintf(&msg, "[%d] %u.%06d: %s\n", (int)getpid(),
                  (unsigned int)sec, (int)usec, str) < 0)