aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-11-29 18:13:58 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2017-11-29 18:20:50 +0100
commit4cf8ee09b51ff41018fbdace63d71a07adf88a09 (patch)
tree21b6980a8b440a4b81b91533fe604cd0fe90759a
parent48ecf6eed5091bdb4788da0112870e79d58baf19 (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.c35
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)