From 9db64aedbfe2815e827fd7ba323cdc84f88c5178 Mon Sep 17 00:00:00 2001 From: Roman Tsisyk <roman@tarantool.org> Date: Thu, 17 Aug 2017 16:59:16 +0300 Subject: [PATCH] lua: add '-' command line option `tarantool -` now executes stdin instead of trying open "./-" script. A part of #1265 --- src/lua/init.c | 4 ++-- src/main.cc | 8 ++++---- test/box-py/args.result | 4 ++++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/lua/init.c b/src/lua/init.c index 99616d6a33..646b7f2f03 100644 --- a/src/lua/init.c +++ b/src/lua/init.c @@ -545,12 +545,12 @@ run_script_f(va_list ap) */ fiber_sleep(0.0); - if (path && access(path, F_OK) == 0) { + if (path && strcmp(path, "-") != 0 && access(path, F_OK) == 0) { /* Execute script. */ if (luaL_loadfile(L, path) != 0) panic("%s", lua_tostring(L, -1)); lua_main(L, argc, argv); - } else if (!isatty(STDIN_FILENO)) { + } else if (!isatty(STDIN_FILENO) || (path && strcmp(path, "-") == 0)) { /* Execute stdin */ if (luaL_loadfile(L, NULL) != 0) panic("%s", lua_tostring(L, -1)); diff --git a/src/main.cc b/src/main.cc index a0e187086a..0d306433df 100644 --- a/src/main.cc +++ b/src/main.cc @@ -481,8 +481,6 @@ tarantool_free(void) #ifdef ENABLE_GCOV __gcov_flush(); #endif - if (script) - free(script); /* tarantool_lua_free() was formerly reponsible for terminal reset, * but it is no longer called */ @@ -535,6 +533,8 @@ print_help(const char *program) puts(" -e EXPR\t\t\texecute string 'EXPR'"); puts(" -l NAME\t\t\trequire library 'NAME'"); puts(" -i\t\t\t\tenter interactive mode after executing 'SCRIPT'"); + puts(" --\t\t\t\tstop handling options"); + puts(" -\t\t\t\texecute stdin and stop handling options"); puts(""); puts("Please visit project home page at http://tarantool.org"); puts("to see online documentation, submit bugs or contribute a patch."); @@ -604,7 +604,7 @@ main(int argc, char **argv) for (int i = 1; i < argc; i++) argv[i] = argv[optind + i - 1]; - if (argc > 1 && access(argv[1], R_OK) != 0) { + if (argc > 1 && strcmp(argv[1], "-") && access(argv[1], R_OK) != 0) { /* * Somebody made a mistake in the file * name. Be nice: open the file to set @@ -636,7 +636,7 @@ main(int argc, char **argv) if (argc > 1) { argv++; argc--; - script = abspath(argv[0]); + script = argv[0]; title_set_script_name(argv[0]); } diff --git a/test/box-py/args.result b/test/box-py/args.result index 3ab6f7b191..11cc9e65a5 100644 --- a/test/box-py/args.result +++ b/test/box-py/args.result @@ -10,6 +10,8 @@ When no script name is provided, the server responds to: -e EXPR execute string 'EXPR' -l NAME require library 'NAME' -i enter interactive mode after executing 'SCRIPT' + -- stop handling options + - execute stdin and stop handling options Please visit project home page at http://tarantool.org to see online documentation, submit bugs or contribute a patch. @@ -26,6 +28,8 @@ When no script name is provided, the server responds to: -e EXPR execute string 'EXPR' -l NAME require library 'NAME' -i enter interactive mode after executing 'SCRIPT' + -- stop handling options + - execute stdin and stop handling options Please visit project home page at http://tarantool.org to see online documentation, submit bugs or contribute a patch. -- GitLab