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 E4C3270310; Wed, 27 Jan 2021 02:38:13 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E4C3270310 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1611704293; bh=Bw27CpJDIodKjAA9IzUba8eUs7pyQJmLuBy0rixuFy0=; 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=xYJapSMspCQ12XMRxQ/LBg7EYvIvZN/XbhOuIlJ4UvxPcTaCoA4dMXpsKmHJNKGtw K+toiLfHXt8WTENkSnKH6zPERi6bANMaJjFrGvUW2sZAuQkHxDzwFC/qszxU35y6wn GggrBHevq9eJRTQUkY+7cny9W+NLpQxBrB3uWdiA= Received: from smtp39.i.mail.ru (smtp39.i.mail.ru [94.100.177.99]) (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 A2951795FC for ; Wed, 27 Jan 2021 02:37:14 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A2951795FC Received: by smtp39.i.mail.ru with esmtpa (envelope-from ) id 1l4XtZ-0002oP-I0; Wed, 27 Jan 2021 02:37:13 +0300 To: Alexander Turenko Date: Wed, 27 Jan 2021 02:37:07 +0300 Message-Id: X-Mailer: git-send-email 2.28.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD92BC6D7A73B5E1EC90D16CF13555D07A24F008FC9AD158C0400894C459B0CD1B9CC45A1A445887E7C18E961F0D6AA4E7479EEC448202F9853EA49DAD9745199E0 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE76C0A440987CA342DC2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE706EA9E10470DC775EA1F7E6F0F101C674E70A05D1297E1BBC6CDE5D1141D2B1CE9973C3D4F28559B0005066A2F9D35241D32FDE3E55F26269FA2833FD35BB23D9E625A9149C048EE1E561CDFBCA1751FC26CFBAC0749D213D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8B1BE95B8C87527B4BA471835C12D1D977C4224003CC836476EB9C4185024447017B076A6E789B0E975F5C1EE8F4F765FCA39938E46083989B3AA81AA40904B5D9CF19DD082D7633A078D18283394535A93AA81AA40904B5D98AA50765F79006375320EBA62BBC5EDFD81D268191BDAD3D698AB9A7B718F8C442539A7722CA490C13377AFFFEAFD26923F8577A6DFFEA7CA54E1600D0FEB00593EC92FD9297F6715571747095F342E857739F23D657EF2BD5E8D9A59859A8B626E28AE78BDC9D44089D37D7C0E48F6C5571747095F342E857739F23D657EF2B6825BDBE14D8E7028C9DFF55498CEFB0BD9CCCA9EDD067B1EDA766A37F9254B7 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CEC4A33FB89DC571C6EFBECDCA0AF102C5F89136360D6CB5A9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EFF532FBFD8162E58C699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34C5CF6F4B28551E3F273833114348E226670AC90CCA934ED1AECA9CD674FDD7B6B5CBF0D78FACA3C61D7E09C32AA3244C2300B6B5EA1979EDAED5DF983C43A1B6B038C9161EF167A183B48618A63566E0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj5ZUBkD5pAd/yizNNEn8V8w== X-Mailru-Sender: 65CD03CFE33A0EC7A4D6F6B2DF798FE60C211C0914160BD73FB535B5B5802D4DBFC86EB6E1CDC663B08A37556DE0CB7BB7E364AFDB3F206FD953F29DB7D76D89B1E6F68DAE724AB9112434F685709FCF0DA7A0AF5A3A8387 X-Mras: Ok Subject: [Tarantool-patches] [PATCH 2/3] 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". --- 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