0

I've got a question. Why cannot I get access to a file from Tarantool LUA admin console? Am I in a jail ?

tarantool -h myhost -a 33015
help

console client commands:
- help
- loadfile 'path'
- setopt key=val
- (possible pairs: delimiter = 'string' )
- ( pager = 'command' )
...
---
available commands:
- help
- exit
- show info
- show fiber
- show configuration
- show slab
- show palloc
- show stat
- show plugins
- save coredump
- save snapshot
- lua command
- reload configuration
- show injections (debug mode only)
- set injection <name> <state> (debug mode only)
...


myhost> lua file = io.open("/etc/motd", "r")

attempt to index global ''io''

Neither I can use a socket module:

[string "local s=require(''socket'');local t=assert(s.tc..."]:1: attempt to call global ''require''

Is it possible at all to read files and execute commands from inside Tarantool LUA console ?

1 Answers1

0

Lua is an extensible, embeddable language. There's no requirement that host programs using the language open the standard libraries. As such, not all programs utilizing Lua will open the io or package libraries. Instead, they may choose to implement, and subsequently open, their own libraries.

The Tarantool module you are looking for is fio, and the similarly named fio.open.

file_handle = fio.open('/etc/motd', { 'O_RDONLY' })

Note that Tarantool has a built-in socket module, as well.


Sources:

Oka
  • 23,367
  • 6
  • 42
  • 53
  • Thank you for your quick response, but this does not seem to be a working solution - lua file_handle = fio.open('/etc/motd', { 'O_RDONLY' }) --- error: '[string "file_handle = fio.open(''/etc/motd'', { ''O_RDON..."]:1: attempt to index global ''fio'' (a nil value)' – Aleh Boitsau Oct 30 '16 at 09:04
  • Close but no cigar( attempt to index global ''fio'' (a nil value)' – Aleh Boitsau Oct 30 '16 at 09:07
  • @AlehBoitsau Yeah, it looks as though I'm slightly mistaken. It seems as though they do open standard libs, and as such you need to use `require` to open their modules - but your instance of `tarantool` doesn't appear to have any standard libs. Perhaps you should update your question with your Tarantool version / operating system, and how you built and installed the program. – Oka Oct 30 '16 at 09:54
  • @AlehBoitsau Also, `tarantool -h -a ` doesn't seem to be valid in versions 1.6 or 1.7. Playing around in my environment, I use the sister application `tarantoolctl` to connect to an application server, and I don't prefix Lua code with `lua`. Note however, that I've never used this program before today. Maybe our configurations are wildly different. – Oka Oct 30 '16 at 09:57