From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id EC4726EC59; Fri, 29 Jan 2021 16:36:56 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EC4726EC59 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1611927417; bh=QQRavCWPpiSsxaiBrpA0HPkViM9rbWbxzQNoqteJUiA=; h=To:References:Date:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=vDAzDLgez1ca20KCo7R6eexiB1AhA0iYF1jOlfBE9l9VnMp3EDy/CEHbvjN33BWNs PV04ommkD6JeAkq8KcpJRe3B9L83Zaev4NNHwAzbqywcfHSk7xb6oqcdBA6/TGQF56 utRwdiuobu4JvRoTtBRW3yqdC03pnuac1RAMuUyk= Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id C4FDA6EC59 for ; Fri, 29 Jan 2021 16:36:55 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C4FDA6EC59 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1l5TxG-0002lq-NJ; Fri, 29 Jan 2021 16:36:55 +0300 To: Artem Starshov , Alexander Turenko References: <02f1ac5691a6f31117d9c72822466942d4737ca7.1611781593.git.artemreyt@tarantool.org> Message-ID: Date: Fri, 29 Jan 2021 16:36:54 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <02f1ac5691a6f31117d9c72822466942d4737ca7.1611781593.git.artemreyt@tarantool.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD953AC099BC0052A9CC9F923E808BA4A11AAD7C69F0036037C182A05F5380850408469B41C7ECC3430EC0CF5C6BBCD28014F2D960F97BC6CB8AAFDA62783453CE5 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE745C0EDBD94D46193EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637188F5654332B449D8638F802B75D45FF5571747095F342E8C7A0BC55FA0FE5FCC33E82CAC15F6678B5AE13ECFA20D0850D52822172B75170389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C0A29E2F051442AF778941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B652D31B9D28593E51CC7F00164DA146DA6F5DAA56C3B73B23C77107234E2CFBA567F23339F89546C55F5C1EE8F4F765FCFBCBFC5051A70ADB75ECD9A6C639B01BBD4B6F7A4D31EC0BC0CAF46E325F83A522CA9DD8327EE493B89ED3C7A62817815E97997F8902A7B9C4224003CC836476C0CAF46E325F83A50BF2EBBBDD9D6B0F05F538519369F3743B503F486389A921A5CC5B56E945C8DA X-C1DE0DAB: 0D63561A33F958A5ECBB18E787BAE1FC2FD3A710E512E7B1C8E09F5C6A3ED663D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA75F04B387B5D7535DE410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D346C409ABC5F9C579BCF25CDFCB17CC25D07CAE56F373DD25638B7ABD0EFA913CCA880D8623975545C1D7E09C32AA3244C46CA3983114285FD187F11642428CAE6B4DF56057A86259F927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj0axADxPFAF8wusFjyXKlpQ== X-Mailru-Sender: 689FA8AB762F73936BC43F508A063822AD77C953C3DEDA9D5277E13EC142C909DD788429FD8613638ED9BB8B05EE7B3AFB559BB5D741EB96D19CD4E7312BAA970A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH 1/2] core: add setting error injections via env X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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();