From: Sergey Bronnikov via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: Artem Starshov <artemreyt@tarantool.org>, Alexander Turenko <alexander.turenko@tarantool.org> Cc: tarantool-patches@dev.tarantool.org Subject: Re: [Tarantool-patches] [PATCH 1/2] core: add setting error injections via env Date: Fri, 29 Jan 2021 16:36:54 +0300 [thread overview] Message-ID: <dd42eaf6-ad23-cd08-1400-2ff2d93cfcfb@tarantool.org> (raw) In-Reply-To: <02f1ac5691a6f31117d9c72822466942d4737ca7.1611781593.git.artemreyt@tarantool.org> Thanks for the patch! See my 4 comments below. On 28.01.2021 00:15, Artem Starshov wrote: > 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. 1. This commit is required by next commit with fix. I propose to link it to issue too by adding "Part of #5040". > > 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() { 2. With function name it is not clear what function does. Please consider rename. For example 'set_errinj_with_environment_vars' or something else. > + for (enum errinj_id i = 0 ; i < errinj_id_MAX ; i++) { 3. What for added these whitespaces before commas? > + 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; > + } > + } > +} 4. Let's add a simple test that will pass three error injection variables with different types (bool, int and double) via environment and check that error injections that same in Lua. > 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 prev parent reply other threads:[~2021-01-29 13:36 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-01-27 21:15 [Tarantool-patches] [PATCH 0/2] lua: fix -e always enters interactive mode Artem Starshov via Tarantool-patches 2021-01-27 21:15 ` [Tarantool-patches] [PATCH 1/2] core: add setting error injections via env Artem Starshov via Tarantool-patches 2021-01-28 15:37 ` Artem via Tarantool-patches 2021-01-29 13:36 ` Sergey Bronnikov via Tarantool-patches [this message] 2021-01-27 21:15 ` [Tarantool-patches] [PATCH 2/2] lua: fix tarantool -e always enters interactive mode Artem Starshov via Tarantool-patches 2021-01-29 13:44 ` Sergey Bronnikov via Tarantool-patches 2021-01-29 13:00 ` [Tarantool-patches] [PATCH 0/2] lua: fix " Sergey Bronnikov via Tarantool-patches
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=dd42eaf6-ad23-cd08-1400-2ff2d93cfcfb@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=alexander.turenko@tarantool.org \ --cc=artemreyt@tarantool.org \ --cc=sergeyb@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH 1/2] core: add setting error injections via env' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox