From 2195a00dc5b70636ccf57563cf907cb3a4b62afc Mon Sep 17 00:00:00 2001 From: José Bollo Date: Wed, 29 Nov 2017 18:13:58 +0100 Subject: afb-config: Check environment variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The following environment variables allows several setting by the environment: * AFB_TRACEREQ, AFB_TRACEDITF, AFB_TRACESVC, AFB_TRACEEVT These variables allows setting of options --tracereq, --traceditf, --tracesvc, --traceevt * AFB_LDPATHS Set the option --ldpaths Change-Id: I22700c658ce3fa1ceb15eab8f67adaaf41627b8f Signed-off-by: José Bollo --- src/afb-config.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/afb-config.c b/src/afb-config.c index 016da835..f4aed055 100644 --- a/src/afb-config.c +++ b/src/afb-config.c @@ -754,12 +754,47 @@ void afb_config_dump(struct afb_config *config) #undef NN } +static void on_environment_list(struct afb_config_list **to, const char *name) +{ + char *value = getenv(name); + + if (value) + list_add(to, value); +} + +static void on_environment_enum(int *to, const char *name, struct enumdesc *desc) +{ + char *value = getenv(name); + + if (value) { + while (desc->name) { + if (strcmp(desc->name, value)) + desc++; + else { + *to = desc->value; + return; + } + } + WARNING("Unknown value %s for environment variable %s, ignored", value, name); + } +} + +static void parse_environment(struct afb_config *config) +{ + on_environment_enum(&config->tracereq, "AFB_TRACEREQ", tracereq_desc); + on_environment_enum(&config->traceditf, "AFB_TRACEDITF", traceditf_desc); + on_environment_enum(&config->tracesvc, "AFB_TRACESVC", tracesvc_desc); + on_environment_enum(&config->traceevt, "AFB_TRACEEVT", traceevt_desc); + on_environment_list(&config->ldpaths, "AFB_LDPATHS"); +} + struct afb_config *afb_config_parse_arguments(int argc, char **argv) { struct afb_config *result; result = calloc(1, sizeof *result); + parse_environment(result); parse_arguments(argc, argv, result); fulfill_config(result); if (verbosity >= 3) -- cgit 1.2.3-korg