From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> To: olegrok@tarantool.org, imun@tarantool.org Cc: tarantool-patches@dev.tarantool.org Subject: Re: [Tarantool-patches] [PATCH] fio: provide access to stdin/stdout/stderr Date: Sun, 26 Apr 2020 19:47:24 +0200 [thread overview] Message-ID: <782c44c5-7cbc-b6e6-bce3-ceeda5840837@tarantool.org> (raw) In-Reply-To: <20200404095315.32905-1-olegrok@tarantool.org> Hi! Thanks for the patch! On 04/04/2020 11:53, olegrok@tarantool.org wrote: > From: Oleg Babin <babinoleg@mail.ru> > > This patch introduces fio API for interaction with > stdin/stdout/stderr streams. > > Closes #1338 > > @TarantoolBot document > Title: fio provides access to stdin/stdout/stderr > > Now access to standard streams is available via: > * fio.stdin > * fio.stdout > * fio.stderr > > Each of this streams have usual fio file interface. > > Example: > ```lua > fio.stdin:read(5) -- read 5 bytes from stdin I tried these examples: 1. Start interactive console, call fio.stdin:read(5). When I type any character, read() returns immediately, with 1 byte read. Not 5. 2. I tried starting Tarantool from a script, without the console. In the script I did essentially the same - call fio.stdin:read(5), print result, exit. It returned only what I inserted until \n or 5 symbols, if I didn't print \n. Why? > fio.stdout:write("Hello") -- write "Hello" to stdout > fio.stderr:write("Error") -- write "Error" to stderr > ``` > --- > Issue: https://github.com/tarantool/tarantool/issues/1338 > Branch: https://github.com/tarantool/tarantool/tree/olegrok/1338-fio-std-streams > > @ChangeLog > - fio provides access to stdin/stdout/stderr (gh-1338) > > src/lua/fio.lua | 10 ++++++++++ > test/app/fio.result | 27 +++++++++++++++++++++++++++ > test/app/fio.test.lua | 11 +++++++++++ > 3 files changed, 48 insertions(+) > > diff --git a/src/lua/fio.lua b/src/lua/fio.lua > index 83fddaa0a..1eaa085ae 100644 > --- a/src/lua/fio.lua > +++ b/src/lua/fio.lua > @@ -522,6 +528,10 @@ fio.utime = function(path, atime, mtime) > return internal.utime(path, atime, mtime) > end > > +fio.stdin = ffi.new('struct fio_handle', filenos.STDIN) > +fio.stdout = ffi.new('struct fio_handle', filenos.STDOUT) > +fio.stderr = ffi.new('struct fio_handle', filenos.STDERR) The problem is that when Tarantool will be terminated, Lua is destroyed (probably it is disabled now, but I think will be enabled at some day). Anyway, destruction of these handles leads to closure of their descriptors, since fio handles now are automatically closed when GC gets to them. That makes all printf(), scanf(), fscanf(), etc, work with invalid descriptors, or even already newly opened descriptors, not related to the standard streams which took their place. Better use dup() so as close of these descriptors wouldn't affect other code.
prev parent reply other threads:[~2020-04-26 17:47 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-04-04 9:53 olegrok 2020-04-26 17:47 ` Vladislav Shpilevoy [this message]
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=782c44c5-7cbc-b6e6-bce3-ceeda5840837@tarantool.org \ --to=v.shpilevoy@tarantool.org \ --cc=imun@tarantool.org \ --cc=olegrok@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH] fio: provide access to stdin/stdout/stderr' \ /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