diff options
author | José Bollo <jose.bollo@iot.bzh> | 2017-11-29 18:13:58 +0100 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2017-11-30 07:33:31 +0100 |
commit | 2195a00dc5b70636ccf57563cf907cb3a4b62afc (patch) | |
tree | ea9dc7a2becece3ad09f7335aa0dff874fc328fd | |
parent | 5c37868e54ee04f51987477e2b87632fc49501f3 (diff) |
afb-config: Check environment variables
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 <jose.bollo@iot.bzh>
-rw-r--r-- | src/afb-config.c | 35 |
1 files changed, 35 insertions, 0 deletions
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) |