commit 59df0c3ec2ec5e3e1872d2aa28e1cf26c452aff4 from: Sergey Bronnikov date: Sat Apr 29 09:26:06 2023 UTC main: require --script for setting path to a script Patch forbids setting path to a Lua script without option -s/--script and document option in usage and manual page. Closes #8612 NO_CHANGELOG=internal NO_DOC=internal NO_TEST=internal commit - c53779fd10c67fd559de75e964b2fd6c7afaed1a commit + 59df0c3ec2ec5e3e1872d2aa28e1cf26c452aff4 blob - eed38e8cba3737584d953aea6679559c1e2d6df4 blob + 8d9871bf046c6a1654f44c36a4305f3b1a1e19d6 --- doc/man/tarantool.pod +++ doc/man/tarantool.pod @@ -63,6 +63,10 @@ Display the help screen and exit. Print the program version and exit. +=item -s, --script + +Set a path to a Lua script file. + =item -e EXRP Execute the string 'EXPR'. blob - a9eeb749e2b68bdbfee9affeba361445bb0b7fba blob + c2b79640d6ed70e1c491da269a71ef7956af5c80 --- src/main.cc +++ src/main.cc @@ -618,12 +618,13 @@ print_help(const char *program) { puts("Tarantool - a Lua application server"); puts(""); - printf("Usage: %s script.lua [OPTIONS] [SCRIPT [ARGS]]\n", program); + printf("Usage: %s [OPTIONS] [--script SCRIPT [ARGS]]\n", program); puts(""); puts("All command line options are passed to the interpreted script."); puts("When no script name is provided, the server responds to:"); puts(" -h, --help\t\t\tdisplay this help and exit"); puts(" -v, --version\t\t\tprint program version and exit"); + puts(" -s, --script \t\tset a path to a Lua script file"); puts(" -e EXPR\t\t\texecute string 'EXPR'"); puts(" -l NAME\t\t\trequire library 'NAME'"); puts(" -j cmd\t\t\tperform LuaJIT control command"); @@ -737,26 +738,6 @@ main(int argc, char **argv) argc = 1 + (argc - optind); for (int i = 1; i < argc; i++) argv[i] = argv[optind + i - 1]; - /* - * The corresponding check is omitted for `O_BYTECODE` - * since it is present in `bcsave.lua` module, which - * performs the bytecode dump. - */ - if (!(opt_mask & O_BYTECODE) && 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 - * errno. - */ - int fd = open(argv[1], O_RDONLY); - int save_errno = errno; - if (fd >= 0) - close(fd); - printf("Can't open script %s: %s\n", - argv[1], tt_strerror(save_errno)); - return save_errno; - } argv = title_init(argc, argv); /* @@ -773,12 +754,8 @@ main(int argc, char **argv) const char *tarantool_bin = find_path(argv[0]); if (!tarantool_bin) tarantool_bin = argv[0]; - if (argc > 1) { - argv++; - argc--; - script = argv[0]; + if (script) title_set_script_name(argv[0]); - } strlcpy(tarantool_path, tarantool_bin, sizeof(tarantool_path)); if (strlen(tarantool_path) < strlen(tarantool_bin)) panic("executable path is trimmed");