diff options
author | Dr. Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com> | 2019-03-21 18:27:50 +0100 |
---|---|---|
committer | Dr. Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com> | 2019-03-30 00:01:55 +0100 |
commit | 02bd2d7f5ce30928baf11226fa31125337251e49 (patch) | |
tree | f81f490c3e672c5901adb4ff2771ada0178c3fe9 /apps/openssl.c | |
parent | 6a411436a5642a4c2ca934a649eced7118f3793d (diff) |
trace: apps/openssl: print the correct category name
Previously, if the openssl application was run with OPENSSL_TRACE=any,
all trace output would just show 'ANY' as the category name, which was
not very useful. To get the correct category name printed in the trace
output, the openssl application now registers separate channels for
each category.
The trace API is unchanged, it is still possible for an application to
register a single channel for the 'ANY' category to see all outputt,
if it does not need this level of detail.
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/8552)
Diffstat (limited to 'apps/openssl.c')
-rw-r--r-- | apps/openssl.c | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/apps/openssl.c b/apps/openssl.c index 44dbda7625..a63f82b15b 100644 --- a/apps/openssl.c +++ b/apps/openssl.c @@ -185,6 +185,33 @@ static void cleanup_trace(void) sk_tracedata_pop_free(trace_data_stack, tracedata_free); } +static void setup_trace_category(int category) +{ + BIO *channel; + tracedata *trace_data; + + if (OSSL_trace_enabled(category)) + return; + + channel = BIO_push(BIO_new(apps_bf_prefix()), + dup_bio_err(FORMAT_TEXT)); + trace_data = OPENSSL_zalloc(sizeof(*trace_data)); + + if (trace_data == NULL + || (trace_data->bio = channel) == NULL + || OSSL_trace_set_callback(category, internal_trace_cb, + trace_data) == 0 + || sk_tracedata_push(trace_data_stack, trace_data) == 0) { + + fprintf(stderr, + "warning: unable to setup trace callback for category '%s'.\n", + OSSL_trace_get_category_name(category)); + + OSSL_trace_set_callback(category, NULL, NULL); + BIO_free_all(channel); + } +} + static void setup_trace(const char *str) { char *val; @@ -199,26 +226,15 @@ static void setup_trace(const char *str) for (valp = val; (item = strtok(valp, ",")) != NULL; valp = NULL) { int category = OSSL_trace_get_category_num(item); - if (category >= 0) { - BIO *channel = BIO_push(BIO_new(apps_bf_prefix()), - dup_bio_err(FORMAT_TEXT)); - tracedata *trace_data = OPENSSL_zalloc(sizeof(*trace_data)); - - if (trace_data == NULL - || (trace_data->bio = channel) == NULL - || OSSL_trace_set_callback(category, internal_trace_cb, - trace_data) == 0 - || sk_tracedata_push(trace_data_stack, trace_data) == 0) { - OSSL_trace_set_callback(category, NULL, NULL); - BIO_free_all(channel); - fprintf(stderr, - "warning: unable to setup trace callback for category '%s'.\n", - item); - } + if (category == OSSL_TRACE_CATEGORY_ANY) { + while (++category < OSSL_TRACE_CATEGORY_NUM) + setup_trace_category(category); + break; + } else if (category > 0) { + setup_trace_category(category); } else { fprintf(stderr, - "warning: unknown trace category: '%s'.\n", - item); + "warning: unknown trace category: '%s'.\n", item); } } } |