several fixes in return value handling

This commit is contained in:
BVK Chaitanya 2010-01-26 12:32:24 +05:30
parent c1273662b9
commit 3342306cec
5 changed files with 27 additions and 15 deletions

View file

@ -13,3 +13,8 @@
* util/grub-script-check.c (grub_script_execute_cmdwhile): New * util/grub-script-check.c (grub_script_execute_cmdwhile): New
function. function.
* tests/grub_script_while1.in: New testcase.
* conf/tests.rmk: New testcase make rule.
* commands/true.c (grub_cmd_false): Remove printing error message.
* commands/test.c (grub_cmd_test): Likewise.

View file

@ -412,8 +412,7 @@ grub_cmd_test (grub_command_t cmd __attribute__ ((unused)),
if (argc >= 1 && grub_strcmp (args[argc - 1], "]") == 0) if (argc >= 1 && grub_strcmp (args[argc - 1], "]") == 0)
argc--; argc--;
return test_parse (args, &argn, argc) ? GRUB_ERR_NONE return test_parse (args, &argn, argc) ? 0 : 1;
: grub_error (GRUB_ERR_TEST_FAILURE, "false");
} }
static grub_command_t cmd_1, cmd_2; static grub_command_t cmd_1, cmd_2;

View file

@ -34,7 +34,7 @@ grub_cmd_false (struct grub_command *cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)), int argc __attribute__ ((unused)),
char *argv[] __attribute__ ((unused))) char *argv[] __attribute__ ((unused)))
{ {
return grub_error (GRUB_ERR_TEST_FAILURE, "false"); return 1;
} }
static grub_command_t cmd_true, cmd_false; static grub_command_t cmd_true, cmd_false;

View file

@ -53,6 +53,9 @@ grub_script_vars1_SOURCES = tests/grub_script_vars1.in
check_SCRIPTS += grub_script_for1 check_SCRIPTS += grub_script_for1
grub_script_for1_SOURCES = tests/grub_script_for1.in grub_script_for1_SOURCES = tests/grub_script_for1.in
check_SCRIPTS += grub_script_while1
grub_script_while1_SOURCES = tests/grub_script_while1.in
# List of tests to execute on "make check" # List of tests to execute on "make check"
# SCRIPTED_TESTS = example_scripted_test # SCRIPTED_TESTS = example_scripted_test
# SCRIPTED_TESTS += example_grub_script_test # SCRIPTED_TESTS += example_grub_script_test
@ -63,6 +66,7 @@ SCRIPTED_TESTS = grub_script_echo1
SCRIPTED_TESTS += grub_script_echo_keywords SCRIPTED_TESTS += grub_script_echo_keywords
SCRIPTED_TESTS += grub_script_vars1 SCRIPTED_TESTS += grub_script_vars1
SCRIPTED_TESTS += grub_script_for1 SCRIPTED_TESTS += grub_script_for1
SCRIPTED_TESTS += grub_script_while1
# dependencies between tests and testing-tools # dependencies between tests and testing-tools
$(SCRIPTED_TESTS): grub-shell grub-shell-tester $(SCRIPTED_TESTS): grub-shell grub-shell-tester

View file

@ -26,13 +26,24 @@
#include <grub/lib/arg.h> #include <grub/lib/arg.h>
#include <grub/normal.h> #include <grub/normal.h>
/* Max digits for a char is 3 (0xFF is 255), similarly for an int it
is sizeof (int) * 3, and one extra for a possible -ve sign. */
#define ERRNO_DIGITS_MAX (sizeof (int) * 3 + 1)
static grub_err_t static grub_err_t
grub_script_execute_cmd (struct grub_script_cmd *cmd) grub_script_execute_cmd (struct grub_script_cmd *cmd)
{ {
int ret;
char errnobuf[ERRNO_DIGITS_MAX + 1];
if (cmd == 0) if (cmd == 0)
return 0; return 0;
return cmd->exec (cmd); ret = cmd->exec (cmd);
grub_snprintf (errnobuf, sizeof (errnobuf), "%d", ret);
grub_env_set ("?", errnobuf);
return ret;
} }
/* Expand arguments in ARGLIST into multiple arguments. */ /* Expand arguments in ARGLIST into multiple arguments. */
@ -188,7 +199,6 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)
grub_err_t ret = 0; grub_err_t ret = 0;
int argcount = 0; int argcount = 0;
grub_script_function_t func = 0; grub_script_function_t func = 0;
char errnobuf[18];
char *cmdname; char *cmdname;
/* Lookup the command. */ /* Lookup the command. */
@ -222,11 +232,7 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)
grub_env_set (assign, eq); grub_env_set (assign, eq);
} }
grub_free (assign); grub_free (assign);
return grub_errno;
grub_snprintf (errnobuf, sizeof (errnobuf), "%d", grub_errno);
grub_env_set ("?", errnobuf);
return 0;
} }
} }
@ -241,9 +247,6 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)
grub_free (args[i]); grub_free (args[i]);
grub_free (args); grub_free (args);
grub_snprintf (errnobuf, sizeof (errnobuf), "%d", ret);
grub_env_set ("?", errnobuf);
return ret; return ret;
} }
@ -251,13 +254,14 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)
grub_err_t grub_err_t
grub_script_execute_cmdblock (struct grub_script_cmd *cmd) grub_script_execute_cmdblock (struct grub_script_cmd *cmd)
{ {
int ret = 0;
struct grub_script_cmdblock *cmdblock = (struct grub_script_cmdblock *) cmd; struct grub_script_cmdblock *cmdblock = (struct grub_script_cmdblock *) cmd;
/* Loop over every command and execute it. */ /* Loop over every command and execute it. */
for (cmd = cmdblock->cmdlist; cmd; cmd = cmd->next) for (cmd = cmdblock->cmdlist; cmd; cmd = cmd->next)
grub_script_execute_cmd (cmd); ret = grub_script_execute_cmd (cmd);
return 0; return ret;
} }
/* Execute an if statement. */ /* Execute an if statement. */