[Tarantool-patches] [PATCH 1/2] core: add setting error injections via env
Artem
artemreyt at tarantool.org
Thu Jan 28 18:37:56 MSK 2021
Fixed mistake in function `errinj_scan_env` when check strcmp(env_value,
"FALSE") and strcmp(env_value, "TRUE").
(Didn't compare it with 0)
--- a/src/lib/core/errinj.c
+++ b/src/lib/core/errinj.c
@@ -66,3 +66,29 @@ int errinj_foreach(errinj_cb cb, void *cb_ctx) {
}
return 0;
}
+
+void errinj_scan_env() {
+ for (enum errinj_id i = 0 ; i < errinj_id_MAX ; i++) {
+ struct errinj *inj = &errinjs[i];
+ const char *env_value = getenv(inj->name);
+ if (!env_value || *env_value == '\0')
+ continue;
+
+ if (inj->type == ERRINJ_INT) {
+ char *end;
+ int64_t int_value = strtoll(env_value, &end, 10);
+ if (*end == '\0')
+ inj->iparam = int_value;
+ } else if (inj->type == ERRINJ_BOOL) {
+ if (strcmp(env_value, "false") == 0 || strcmp(env_value, "FALSE") == 0)
+ inj->bparam = false;
+ else if (strcmp(env_value, "true") == 0 || strcmp(env_value, "TRUE") == 0)
+ inj->bparam = true;
+ } else if (inj->type == ERRINJ_DOUBLE) {
+ char *end;
+ double double_value = strtod(env_value, &end);
+ if (*end == '\0')
+ inj->dparam = double_value;
+ }
+ }
+}
28.01.2021 00:15, Artem Starshov пишет:
> Sometimes, it's useful to set error injections via environment
> variables and this commit adds this opportunity.
>
> e.g: `ERRINJ_WAL_WRITE=true tarantool` will be launched with
> ERRINJ_WAL_WRITE setted to true.
>
> Errinjs with bool parameters can should be set as "true", "TRUE",
> "false" or "FALSE".
>
> Errinjs with int or double parameters should be whole valid ("123s" is invalid).
> e.g. for int or double: "123", "-1", "2.34", "+2.34".
> ---
> @ChangeLog: Fixed -e option, when tarantool always entered interactive mode when
> stdin is a tty. Now, `tarantool -e 'print"Hello"'` doesn't enter interactive mode
> as it was before.
>
> src/lib/core/errinj.c | 26 ++++++++++++++++++++++++++
> src/lib/core/errinj.h | 5 +++++
> src/main.cc | 1 +
> 3 files changed, 32 insertions(+)
>
> diff --git a/src/lib/core/errinj.c b/src/lib/core/errinj.c
> index d3aa0ca4f..576811073 100644
> --- a/src/lib/core/errinj.c
> +++ b/src/lib/core/errinj.c
> @@ -66,3 +66,29 @@ int errinj_foreach(errinj_cb cb, void *cb_ctx) {
> }
> return 0;
> }
> +
> +void errinj_scan_env() {
> + for (enum errinj_id i = 0 ; i < errinj_id_MAX ; i++) {
> + struct errinj *inj = &errinjs[i];
> + const char *env_value = getenv(inj->name);
> + if (!env_value || *env_value == '\0')
> + continue;
> +
> + if (inj->type == ERRINJ_INT) {
> + char *end;
> + int64_t int_value = strtoll(env_value, &end, 10);
> + if (*end == '\0')
> + inj->iparam = int_value;
> + } else if (inj->type == ERRINJ_BOOL) {
> + if (strcmp(env_value, "false") == 0 || strcmp(env_value, "FALSE"))
> + inj->bparam = false;
> + else if (strcmp(env_value, "true") == 0 || strcmp(env_value, "TRUE"))
> + inj->bparam = true;
> + } else if (inj->type == ERRINJ_DOUBLE) {
> + char *end;
> + double double_value = strtod(env_value, &end);
> + if (*end == '\0')
> + inj->dparam = double_value;
> + }
> + }
> +}
> diff --git a/src/lib/core/errinj.h b/src/lib/core/errinj.h
> index 814c57c2e..dc0657614 100644
> --- a/src/lib/core/errinj.h
> +++ b/src/lib/core/errinj.h
> @@ -168,6 +168,11 @@ typedef int (*errinj_cb)(struct errinj *e, void *cb_ctx);
> int
> errinj_foreach(errinj_cb cb, void *cb_ctx);
>
> +/**
> + * Set injections by scanning ERRINJ_$(NAME) in environment variables
> + */
> +void errinj_scan_env();
> +
> #ifdef NDEBUG
> # define ERROR_INJECT(ID, CODE)
> # define ERROR_INJECT_WHILE(ID, CODE)
> diff --git a/src/main.cc b/src/main.cc
> index 2fce81bb3..2d85c0b24 100644
> --- a/src/main.cc
> +++ b/src/main.cc
> @@ -710,6 +710,7 @@ main(int argc, char **argv)
> memtx_tx_manager_init();
> crypto_init();
> systemd_init();
> + errinj_scan_env();
> tarantool_lua_init(tarantool_bin, main_argc, main_argv);
>
> start_time = ev_monotonic_time();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.tarantool.org/pipermail/tarantool-patches/attachments/20210128/2b46c77a/attachment.htm>
More information about the Tarantool-patches
mailing list