From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> To: tarantool-patches@freelists.org Cc: vdavydov.dev@gmail.com Subject: [PATCH v2 1/4] console: forbid arbitrary session type setting Date: Tue, 11 Dec 2018 19:10:20 +0300 [thread overview] Message-ID: <ec29126770e427e5030a35408073a137c2eb0dca.1544544183.git.v.shpilevoy@tarantool.org> (raw) In-Reply-To: <cover.1544544183.git.v.shpilevoy@tarantool.org> In-Reply-To: <cover.1544544183.git.v.shpilevoy@tarantool.org> The only place where session type is changed after its creation is console. Console sets 'repl' session type once console.start() is called, or 'console', if a remote client connected to console server using console.connect(). But function to set session type is too common. Using it any other session type can be set. Even console can be changed to applier or binary. Lets split it into two more specific functions setting only 'repl' and 'console'. Also, it simplifies next patches, making vtab part of struct session. --- src/box/lua/console.lua | 4 ++-- src/box/lua/session.c | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua index 028001127..19ea4bb0a 100644 --- a/src/box/lua/console.lua +++ b/src/box/lua/console.lua @@ -448,7 +448,7 @@ local function start() self.history_file = home_dir .. '/.tarantool_history' internal.load_history(self.history_file) end - session_internal.create(1, "repl") -- stdin fileno + session_internal.create_repl(1) -- stdin fileno repl(self) started = false end @@ -521,7 +521,7 @@ local function connect(uri, opts) end local function client_handler(client, peer) - session_internal.create(client:fd(), "console") + session_internal.create_console(client:fd()) session_internal.run_on_connect() session_internal.run_on_auth(box.session.user(), true) local state = setmetatable({ diff --git a/src/box/lua/session.c b/src/box/lua/session.c index d3d27643f..f4944baea 100644 --- a/src/box/lua/session.c +++ b/src/box/lua/session.c @@ -47,22 +47,33 @@ static const char *sessionlib_name = "box.session"; /* Create session and pin it to fiber */ static int -lbox_session_create(struct lua_State *L) +lbox_session_create(struct lua_State *L, enum session_type type) { struct session *session = fiber_get_session(fiber()); if (session == NULL) { session = session_create_on_demand(); if (session == NULL) return luaT_error(L); - session->meta.fd = luaL_optinteger(L, 1, -1); + session->meta.fd = lua_tointeger(L, 1); } - /* If a session already exists, simply reset its type */ - session->type = STR2ENUM(session_type, luaL_optstring(L, 2, "console")); + session->type = type; lua_pushnumber(L, session->id); return 1; } +static int +lbox_session_create_console(struct lua_State *L) +{ + return lbox_session_create(L, SESSION_TYPE_CONSOLE); +} + +static int +lbox_session_create_repl(struct lua_State *L) +{ + return lbox_session_create(L, SESSION_TYPE_REPL); +} + /** * Return a unique monotonic session * identifier. The identifier can be used @@ -446,7 +457,8 @@ void box_lua_session_init(struct lua_State *L) { static const struct luaL_Reg session_internal_lib[] = { - {"create", lbox_session_create}, + {"create_console", lbox_session_create_console}, + {"create_repl", lbox_session_create_repl}, {"run_on_connect", lbox_session_run_on_connect}, {"run_on_disconnect", lbox_session_run_on_disconnect}, {"run_on_auth", lbox_session_run_on_auth}, -- 2.17.2 (Apple Git-113)
next prev parent reply other threads:[~2018-12-11 16:10 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-12-11 16:10 [PATCH v2 0/4] Outdate binary session on disconnect Vladislav Shpilevoy 2018-12-11 16:10 ` Vladislav Shpilevoy [this message] 2018-12-21 11:17 ` [PATCH v2 1/4] console: forbid arbitrary session type setting Vladimir Davydov 2018-12-11 16:10 ` [PATCH v2 2/4] session: minimize number of session type resets Vladislav Shpilevoy 2018-12-11 16:10 ` [PATCH v2 3/4] session: store vtab in struct session Vladislav Shpilevoy 2018-12-21 11:04 ` Vladimir Davydov 2018-12-21 11:23 ` [tarantool-patches] " Vladislav Shpilevoy 2018-12-11 16:10 ` [PATCH v2 4/4] session: outdate a session of a closed connection Vladislav Shpilevoy
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=ec29126770e427e5030a35408073a137c2eb0dca.1544544183.git.v.shpilevoy@tarantool.org \ --to=v.shpilevoy@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=vdavydov.dev@gmail.com \ --subject='Re: [PATCH v2 1/4] console: forbid arbitrary session type setting' \ /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