From b9dfb8d03b457844fbcab5ad20d744971569f0d7 Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Mon, 27 Jan 2014 19:07:30 -0800 Subject: Add 'ppaml_tracer_init_from_env' This new API function is similar to 'ppaml_tracer_init', but instead of accepting the report base name as an argument, it pulls it from the 'PPAMLTRACER_TRACE_BASE' environment variable. This is useful for users who want to be able to vary the locations of trace reports but do not want to build tracing into their configuration file / command-line argument parsers. --- src/tracer.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src') diff --git a/src/tracer.c b/src/tracer.c index be2f3cc..3b39759 100644 --- a/src/tracer.c +++ b/src/tracer.c @@ -24,6 +24,7 @@ #include #include +#include #include @@ -59,6 +60,23 @@ int ppaml_tracer_init( done: return r; } +int ppaml_tracer_init_from_env(ppaml_tracer_t *const tracer) +{ + int r = 0; + // Figure out where to put the trace. + const char *const report_name_base = getenv("PPAMLTRACER_TRACE_BASE"); + require_nonnull(report_name_base, 5); + if (report_name_base[0] == '\0') { + /* The variable exists, but it's empty, so we can't do anything + * with it. */ + r = 5; + goto done; + } + // Create the trace. + r = ppaml_tracer_init(tracer, report_name_base); +done: return r; +} + int ppaml_tracer_done(ppaml_tracer_t *const tracer) { int r = 0; -- cgit v1.2.3