From: Kirill Yukhin <kyukhin@tarantool.org>
To: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH 2/2] Allow to set directory for copying DSO before load
Date: Wed, 20 May 2020 12:51:18 +0300 [thread overview]
Message-ID: <17830780bc75041a478126ee3d13c96bbd5f8b04.1589968157.git.kyukhin@tarantool.org> (raw)
In-Reply-To: <cover.1589968157.git.kyukhin@tarantool.org>
In-Reply-To: <cover.1589968157.git.kyukhin@tarantool.org>
Make it possible to set temporary directory where
module will be copied before load.
@TarantoolBot document
Title: Justify module (re-)loading semantics
It is now possible to set directory where temporary
copies of modules to be loaded will be created.
It is done by setting $(TMPDIR) variable. It
will be "/tmp" if variable was not set.
Follow up #4945
---
src/box/call.c | 12 ++++++++----
src/box/func.c | 23 +++++++++++++++++++----
test/box/func_reload.result | 30 +++++++++++++++++++++++-------
test/box/func_reload.test.lua | 13 ++++++++++---
4 files changed, 60 insertions(+), 18 deletions(-)
diff --git a/src/box/call.c b/src/box/call.c
index 7c70d81..c16ac70 100644
--- a/src/box/call.c
+++ b/src/box/call.c
@@ -129,10 +129,14 @@ box_module_reload(const char *name)
return -1;
}
struct module *module = NULL;
- if (module_reload(name, name + strlen(name), &module) == 0 &&
- module != NULL)
- return 0;
- diag_set(ClientError, ER_NO_SUCH_MODULE, name);
+ if (module_reload(name, name + strlen(name), &module) == 0) {
+ if (module != NULL)
+ return 0;
+ else {
+ diag_set(ClientError, ER_NO_SUCH_MODULE, name);
+ return -1;
+ }
+ }
return -1;
}
diff --git a/src/box/func.c b/src/box/func.c
index a42a269..0405eb9 100644
--- a/src/box/func.c
+++ b/src/box/func.c
@@ -261,14 +261,29 @@ module_load(const char *package, const char *package_end)
module->package[package_len] = 0;
rlist_create(&module->funcs);
module->calls = 0;
- char dir_name[] = "/tmp/tntXXXXXX";
+
+ const char *tmpdir = getenv("TMPDIR");
+ if (tmpdir == NULL)
+ tmpdir = "/tmp";
+ char dir_name[PATH_MAX + 1];
+ int rc = snprintf(dir_name, sizeof(dir_name), "%s/tntXXXXXX", tmpdir);
+ if (rc < 0 || (size_t) rc >= sizeof(dir_name)) {
+ diag_set(SystemError, "failed to generate path to tmp dir");
+ goto error;
+ }
+
if (mkdtemp(dir_name) == NULL) {
- diag_set(SystemError, "failed to create unique dir name");
+ diag_set(SystemError, "failed to create unique dir name: %s",
+ dir_name);
goto error;
}
char load_name[PATH_MAX + 1];
- snprintf(load_name, sizeof(load_name), "%s/%.*s." TARANTOOL_LIBEXT,
- dir_name, package_len, package);
+ rc = snprintf(load_name, sizeof(load_name), "%s/%.*s." TARANTOOL_LIBEXT,
+ dir_name, package_len, package);
+ if (rc < 0 || (size_t) rc >= sizeof(dir_name)) {
+ diag_set(SystemError, "failed to generate path to DSO");
+ goto error;
+ }
FILE *source, *target;
source = fopen(path, "r");
diff --git a/test/box/func_reload.result b/test/box/func_reload.result
index 1313fdf..fbc2ad7 100644
--- a/test/box/func_reload.result
+++ b/test/box/func_reload.result
@@ -233,20 +233,36 @@ c:call("reload.test_reload_fail")
---
- [[2]]
...
-box.schema.func.drop("reload.test_reload")
+box.schema.func.reload()
---
+- error: 'bad argument #1 to ''?'' (string expected, got no value)'
...
-box.schema.func.drop("reload.test_reload_fail")
+box.schema.func.reload("non-existing")
---
+- error: Module 'non-existing' does not exist
...
-_ = fio.unlink(reload_path)
+-- Make sure that $TMPDIR env variable is used to generate temporary
+-- path for DSO copy
+os.setenv("TMPDIR", "/dev/null")
---
...
-box.schema.func.reload()
+_, err = pcall(box.schema.func.reload, "reload")
---
-- error: 'bad argument #1 to ''?'' (string expected, got no value)'
...
-box.schema.func.reload("non-existing")
+tostring(err):gsub(': [/%w]+$', '')
+---
+- failed to create unique dir name
+- 1
+...
+os.setenv("TMPDIR", nil)
+---
+...
+box.schema.func.drop("reload.test_reload")
+---
+...
+box.schema.func.drop("reload.test_reload_fail")
+---
+...
+_ = fio.unlink(reload_path)
---
-- error: Module 'non-existing' does not exist
...
diff --git a/test/box/func_reload.test.lua b/test/box/func_reload.test.lua
index 4c062fd..5b1b4e9 100644
--- a/test/box/func_reload.test.lua
+++ b/test/box/func_reload.test.lua
@@ -79,9 +79,16 @@ fio.copyfile(reload1_path, reload_path)
c:call("reload.test_reload")
c:call("reload.test_reload_fail")
+box.schema.func.reload()
+box.schema.func.reload("non-existing")
+
+-- Make sure that $TMPDIR env variable is used to generate temporary
+-- path for DSO copy
+os.setenv("TMPDIR", "/dev/null")
+_, err = pcall(box.schema.func.reload, "reload")
+tostring(err):gsub(': [/%w]+$', '')
+os.setenv("TMPDIR", nil)
+
box.schema.func.drop("reload.test_reload")
box.schema.func.drop("reload.test_reload_fail")
_ = fio.unlink(reload_path)
-
-box.schema.func.reload()
-box.schema.func.reload("non-existing")
--
1.8.3.1
next prev parent reply other threads:[~2020-05-20 9:51 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-20 9:51 [Tarantool-patches] [PATCH 0/2] Fix C module reloading Kirill Yukhin
2020-05-20 9:51 ` [Tarantool-patches] [PATCH 1/2] Copy DSO module before load instead of symlink-ing Kirill Yukhin
2020-05-23 18:30 ` Konstantin Osipov
2020-05-25 13:13 ` Kirill Yukhin
2020-05-25 14:34 ` Konstantin Osipov
2020-05-25 15:18 ` Cyrill Gorcunov
2020-05-25 15:26 ` Cyrill Gorcunov
2020-05-25 16:45 ` Konstantin Osipov
2020-05-25 18:38 ` Cyrill Gorcunov
2020-05-26 11:11 ` Kirill Yukhin
2020-05-26 15:16 ` Cyrill Gorcunov
2020-05-27 9:17 ` Kirill Yukhin
2020-05-27 10:49 ` Cyrill Gorcunov
2020-05-20 9:51 ` Kirill Yukhin [this message]
2020-05-29 10:59 ` [Tarantool-patches] [PATCH 2/2] Allow to set directory for copying DSO before load Cyrill Gorcunov
2020-06-01 10:53 ` Kirill Yukhin
2020-05-20 20:41 ` [Tarantool-patches] [PATCH 0/2] Fix C module reloading Nikita Pettik
2020-05-21 8:41 ` Kirill Yukhin
2020-06-01 10:52 ` Kirill Yukhin
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=17830780bc75041a478126ee3d13c96bbd5f8b04.1589968157.git.kyukhin@tarantool.org \
--to=kyukhin@tarantool.org \
--cc=tarantool-patches@dev.tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH 2/2] Allow to set directory for copying DSO before load' \
/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