X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-config.c;h=669bbc570da6174a75d7c17d92387d480f84ed19;hb=408acbdce381f1e70985eae9f96d036689f3d0aa;hp=c10b293754518a0b23c778389f3f77199cfa816f;hpb=5ef271effacb83552f9ea56572c751c2f5a556b6;p=src%2Fapp-framework-binder.git diff --git a/src/afb-config.c b/src/afb-config.c index c10b2937..669bbc57 100644 --- a/src/afb-config.c +++ b/src/afb-config.c @@ -108,12 +108,13 @@ #define SET_TRACESVC 26 #endif +#define SET_TRAP_FAULTS 27 + #if defined(WITH_DBUS_TRANSPARENCY) # define ADD_DBUS_CLIENT 30 # define ADD_DBUS_SERVICE 31 #endif - #define ADD_AUTO_API 'A' #define ADD_BINDING 'b' #define SET_CONFIG 'C' @@ -170,8 +171,8 @@ static struct option_desc optdefs[] = { {SET_CACHE_TIMEOUT, 1, "cache-eol", "Client cache end of live [default " d2s(DEFAULT_CACHE_TIMEOUT) "]"}, {SET_WORK_DIR, 1, "workdir", "Set the working directory [default: $PWD or current working directory]"}, - {SET_UPLOAD_DIR, 1, "uploaddir", "Directory for uploading files [default: workdir]"}, - {SET_ROOT_DIR, 1, "rootdir", "Root Directory of the application [default: workdir]"}, + {SET_UPLOAD_DIR, 1, "uploaddir", "Directory for uploading files [default: workdir] relative to workdir"}, + {SET_ROOT_DIR, 1, "rootdir", "Root Directory of the application [default: workdir] relative to workdir"}, {ADD_LDPATH, 1, "ldpaths", "Load bindings from dir1:dir2:... [default = " BINDING_INSTALL_DIR "]"}, {ADD_BINDING, 1, "binding", "Load the binding of path"}, @@ -220,6 +221,8 @@ static struct option_desc optdefs[] = { {ADD_SET, 1, "set", "Set parameters ([API]/[KEY]:JSON or {\"API\":{\"KEY\":JSON}}" }, {SET_OUTPUT, 1, "output", "Redirect stdout and stderr to output file (when --daemon)"}, + {SET_TRAP_FAULTS, 1, "trap-faults", "Trap faults: on, off, yes, no, true, false, 1, 0 (default: true)"}, + {0, 0, NULL, NULL} /* *INDENT-ON* */ }; @@ -453,6 +456,29 @@ static struct json_object *to_jbool(int value) * arguments helpers ***********************************/ +static int string_to_bool(const char *value) +{ + static const char true_names[] = "1\0yes\0true\0on"; + static const char false_names[] = "0\0no\0false\0off"; + size_t pos; + + pos = 0; + while (pos < sizeof true_names) + if (strcasecmp(value, &true_names[pos])) + pos += 1 + strlen(&true_names[pos]); + else + return 1; + + pos = 0; + while (pos < sizeof false_names) + if (strcasecmp(value, &false_names[pos])) + pos += 1 + strlen(&false_names[pos]); + else + return 0; + + return -1; +} + static void noarg(int optid) { if (optarg) { @@ -471,6 +497,17 @@ static const char *get_arg(int optid) return optarg; } +static int get_arg_bool(int optid) +{ + int value = string_to_bool(get_arg(optid)); + if (value < 0) { + ERROR("option [--%s] needs a boolean value: yes/no, true/false, on/off, 1/0", + name_of_optid(optid)); + exit(1); + } + return value; +} + static void config_del(struct json_object *config, int optid) { return json_object_object_del(config, name_of_optid(optid)); @@ -789,6 +826,11 @@ static void parse_arguments_inner(int argc, char **argv, struct json_object *con config_set_bool(config, SET_DAEMON, optid != SET_FOREGROUND); break; + case SET_TRAP_FAULTS: + config_set_bool(config, optid, get_arg_bool(optid)); + break; + + case SET_TRACEREQ: config_set_optenum(config, optid, afb_hook_flags_xreq_from_text); break; @@ -941,6 +983,20 @@ static void on_environment_enum(struct json_object *config, int optid, const cha } } +static void on_environment_bool(struct json_object *config, int optid, const char *name) +{ + char *value = getenv(name); + int asbool; + + if (value) { + asbool = string_to_bool(value); + if (asbool < 0) + WARNING("Unknown value %s for environment variable %s, ignored", value, name); + else + config_set_bool(config, optid, asbool); + } +} + static void parse_environment(struct json_object *config) { on_environment_enum(config, SET_TRACEREQ, "AFB_TRACEREQ", afb_hook_flags_xreq_from_text); @@ -954,6 +1010,7 @@ static void parse_environment(struct json_object *config) on_environment_enum(config, SET_TRACEDITF, "AFB_TRACEDITF", afb_hook_flags_legacy_ditf_from_text); on_environment_enum(config, SET_TRACESVC, "AFB_TRACESVC", afb_hook_flags_legacy_svc_from_text); #endif + on_environment_bool(config, SET_TRAP_FAULTS, "AFB_TRAP_FAULTS"); } struct json_object *afb_config_parse_arguments(int argc, char **argv)