1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-02 01:18:26 +03:00

commands: fix handing of ENO_SUCH_CMD in script

Fix the error messages when an unrecognized command is
run from a script.  We shouldn't attempt to parse options
for an unrecognized command name, which causes misleading
errors about bad options, but rather exit right when we
know the command name is not valid.  Also don't complain
about exiting without an error message when running a
script if no command didn't exist.
This commit is contained in:
David Teigland 2017-05-08 10:50:27 -05:00
parent 85f1814e9d
commit cf3a6bbbe8

View File

@ -2748,7 +2748,8 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
return_ECMD_FAILED; return_ECMD_FAILED;
/* Look up command - will be NULL if not recognised */ /* Look up command - will be NULL if not recognised */
cmd->cname = find_command_name(cmd->name); if (!(cmd->cname = find_command_name(cmd->name)))
return ENO_SUCH_CMD;
if (!_process_command_line(cmd, &argc, &argv)) { if (!_process_command_line(cmd, &argc, &argv)) {
log_error("Error during parsing of command line."); log_error("Error during parsing of command line.");
@ -2765,10 +2766,6 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
log_debug("Parsing: %s", cmd->cmd_line); log_debug("Parsing: %s", cmd->cmd_line);
/* Having validated cmdline args, return if we didn't recognised the command */
if (!cmd->cname)
return ENO_SUCH_CMD;
if (!(cmd->command = _find_command(cmd, cmd->name, &argc, argv))) if (!(cmd->command = _find_command(cmd, cmd->name, &argc, argv)))
return EINVALID_CMD_LINE; return EINVALID_CMD_LINE;
@ -3293,7 +3290,7 @@ static int _run_script(struct cmd_context *cmd, int argc, char **argv)
{ {
FILE *script; FILE *script;
char buffer[CMD_LEN]; char buffer[CMD_LEN];
int ret = 0; int ret = ENO_SUCH_CMD;
int magic_number = 0; int magic_number = 0;
char *script_file = argv[0]; char *script_file = argv[0];
@ -3328,6 +3325,13 @@ static int _run_script(struct cmd_context *cmd, int argc, char **argv)
if (!strcmp(argv[0], "quit") || !strcmp(argv[0], "exit")) if (!strcmp(argv[0], "quit") || !strcmp(argv[0], "exit"))
break; break;
ret = lvm_run_command(cmd, argc, argv); ret = lvm_run_command(cmd, argc, argv);
/*
* FIXME: handling scripts with invalid or failing commands
* could use some cleaning up, e.g. error_message_produced
* check and error are repeated again in the caller.
*/
if (ret == ENO_SUCH_CMD)
break;
if (ret != ECMD_PROCESSED) { if (ret != ECMD_PROCESSED) {
if (!error_message_produced()) { if (!error_message_produced()) {
log_debug(INTERNAL_ERROR "Failed command did not use log_error"); log_debug(INTERNAL_ERROR "Failed command did not use log_error");