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 AAB2068713; Thu, 28 Jan 2021 18:38:00 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org AAB2068713 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1611848280; bh=wGacZUpNgDO7NnWrzN3UHULmrgWDwki6xUeunLlvlnE=; 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=q5Cs8ZuflGhV7QP8IFKvTlKPg8YqqtnWbO7xEMpsDJlh+NkRxP3oVGUYlDZTlcUz5 kEw3OXCzXR/LqRF3Ix/msjS4M9iw0+DnIM2nUS+l1GENMkFO5fagBHB/0KOfDdT05Z 1VPCX/GfR/3+8ZXMO1Kjb/wedWAsKcXc/Cn6wx3M= Received: from smtp16.mail.ru (smtp16.mail.ru [94.100.176.153]) (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 D69A168713 for ; Thu, 28 Jan 2021 18:37:58 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D69A168713 Received: by smtp16.mail.ru with esmtpa (envelope-from ) id 1l59Mr-0002tY-9k; Thu, 28 Jan 2021 18:37:57 +0300 To: Alexander Turenko References: <02f1ac5691a6f31117d9c72822466942d4737ca7.1611781593.git.artemreyt@tarantool.org> Message-ID: <020e25f9-2a5a-1d3e-9aab-71f1c9d975a5@tarantool.org> Date: Thu, 28 Jan 2021 18:37:56 +0300 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: <02f1ac5691a6f31117d9c72822466942d4737ca7.1611781593.git.artemreyt@tarantool.org> Content-Type: multipart/alternative; boundary="------------BCBB8BEC84EFD42EA159A9FA" Content-Language: ru X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92BC6D7A73B5E1EC9A4696E262F57B05E134BE683453920D000894C459B0CD1B92F9ECBAB9F858073FA2E70F22DD9888201434FDCF352D7A1649674B2D0E99EEF X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE74D0D2DEF2EB846B0EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637F63E14183F8C6AF98638F802B75D45FF5571747095F342E8C7A0BC55FA0FE5FC9748D73506E2B1DC01E9ED47216E0304125AF01A5AE02A6B389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C078FCF50C7EAF9C588941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B6D52CD31C43BF465FCC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB8D32BA5DBAC0009BE9E8FC8737B5C22497071EB8B3FD47F5C3AA81AA40904B5D9CF19DD082D7633A078D18283394535A93AA81AA40904B5D98AA50765F7900637C2E77933D3256844EC76A7562686271EEC990983EF5C032935872C767BF85DA29E625A9149C048EE0A3850AC1BE2E735C2546860BDEA057B4AD6D5ED66289B524E70A05D1297E1BB35872C767BF85DA227C277FBC8AE2E8BF06FF5FC0997E3F8EFF80C71ABB335746BA297DBC24807EA27F269C8F02392CD20465B3A5AADEC6827F269C8F02392CD5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A5A43124F84D736804FB659E0127CA3C849CF918B44CA732EDD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA75F04B387B5D7535DE410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3494FB0335DF05DC3A40F70157E0485604F965439E35D562BF16A74DEC95FD409AD805157AAE7341501D7E09C32AA3244C595B52DC768BDC7CC07708205913A1E7259227199D06760A927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj51JIhz31DSISFTp0XlkRsQ== X-Mailru-Sender: 65CD03CFE33A0EC70FAAED340D76CC87FF6FBC6320297294492CCBDBE82C67FF93B4A7D274D4FA80B08A37556DE0CB7BB7E364AFDB3F206FD953F29DB7D76D89B1E6F68DAE724AB9112434F685709FCF0DA7A0AF5A3A8387 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: Artem via Tarantool-patches Reply-To: Artem Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This is a multi-part message in MIME format. --------------BCBB8BEC84EFD42EA159A9FA Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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(); --------------BCBB8BEC84EFD42EA159A9FA Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

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();
--------------BCBB8BEC84EFD42EA159A9FA--