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 3DE1A68713; Thu, 28 Jan 2021 00:15:54 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 3DE1A68713 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1611782154; bh=yfP5+3KixThjgWNNZDc83fLw8Y9rXKf/PAwXfgMeMTs=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=i+ny8UOlh3AQKH8FEILUH6+UMRWiCqBEUMpXZ9RZ8Mh7EvuOQH8kci6hE83t/9Hld gnnesEXueskkikNOPWves6SR2oaq5gi3Ol2/0nBs7OeVFknOcn0CxCPCAS3Rb/EZNJ lhxHMMKjpRrV9vHNAZGF+YQ/aLJqSMy3Rqphgu/U= Received: from smtp61.i.mail.ru (smtp61.i.mail.ru [217.69.128.41]) (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 B35BC5CD8B for ; Thu, 28 Jan 2021 00:15:23 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org B35BC5CD8B Received: by smtp61.i.mail.ru with esmtpa (envelope-from ) id 1l4s9q-0005K9-M1; Thu, 28 Jan 2021 00:15:23 +0300 To: Alexander Turenko Date: Thu, 28 Jan 2021 00:15:18 +0300 Message-Id: <02f1ac5691a6f31117d9c72822466942d4737ca7.1611781593.git.artemreyt@tarantool.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92BC6D7A73B5E1EC999351CFD198CD6A83B27540038C113F100894C459B0CD1B9DAC7C15386D2CCCE2133118E57BA3B807889768B42F290CDC3F62BCCD34CAD73 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE751DD1FEBB966604DEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006371A00CE7BDCE207EB8638F802B75D45FF5571747095F342E8C7A0BC55FA0FE5FCB308F062B37B2234232EA2FC85254D774D848864F0FD17E7389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C05A64D9A1E9CA65708941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B6B737A621A50BC793CC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB8D32BA5DBAC0009BE9E8FC8737B5C22492C3D642D12E2BBE776E601842F6C81A12EF20D2F80756B5F7E9C4E3C761E06A776E601842F6C81A127C277FBC8AE2E8BC0FF8ADD377BDB973AA81AA40904B5D9DBF02ECDB25306B2B25CBF701D1BE8734AD6D5ED66289B5278DA827A17800CE702060426C7BD36AE67F23339F89546C5A8DF7F3B2552694A6FED454B719173D6725E5C173C3A84C39B1AFFD6BD8BDD3135872C767BF85DA2F004C906525384306FED454B719173D6462275124DF8B9C9DE2850DD75B2526BE5BFE6E7EFDEDCD789D4C264860C145E X-B7AD71C0: 6FEFE4C63DFE2D85469AD6E133326EAB664F5199923B286E81C2AD9CFA0FBF5C9C2BBA594F31363B5803BE1F3B17DC36E8F7B195E1C978314068259DAB7CBBF9B24383D33A8A987E X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CEC4A33FB89DC571C90B062E60F0BC57C581A9AA0E5A665B79C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFF532FBFD8162E58C699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3475FE4AA98865E2353DEB897A8A686D3DE240F1217A71FB4FB3D647FF039077177EB9CE8069FCB8CB1D7E09C32AA3244CFDA1C86513B2FBBE5A1373CDC13881A133C9DC155518937F83B48618A63566E0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj5ZUBkD5pAd80FZdrKtarqg== X-Mailru-Sender: 65CD03CFE33A0EC7A4D6F6B2DF798FE6BC46659AE30EADB75139640818515E42AD49838AFA339EA0B08A37556DE0CB7BB7E364AFDB3F206FD953F29DB7D76D89B1E6F68DAE724AB9112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: [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: Artem Starshov via Tarantool-patches Reply-To: Artem Starshov Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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(); -- 2.28.0