]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
several fixes in return value handling
authorBVK Chaitanya <bvk.groups@gmail.com>
Tue, 26 Jan 2010 07:02:24 +0000 (12:32 +0530)
committerBVK Chaitanya <bvk.groups@gmail.com>
Tue, 26 Jan 2010 07:02:24 +0000 (12:32 +0530)
ChangeLog.while-until-loops
commands/test.c
commands/true.c
conf/tests.rmk
script/execute.c

index 33a3a839d824d534836e87104f4a96b76152612c..ac54b8cd90531bf6862d8bbb878e1167acdf8515 100644 (file)
@@ -13,3 +13,8 @@
        * util/grub-script-check.c (grub_script_execute_cmdwhile): New
        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.
index 6995165cf47f3590bd34dd5b650b8b8d5469ca04..64ad6952216c912c614a9fef4872ea661a270be9 100644 (file)
@@ -412,8 +412,7 @@ grub_cmd_test (grub_command_t cmd __attribute__ ((unused)),
   if (argc >= 1 && grub_strcmp (args[argc - 1], "]") == 0)
     argc--;
 
-  return test_parse (args, &argn, argc) ? GRUB_ERR_NONE
-    : grub_error (GRUB_ERR_TEST_FAILURE, "false");
+  return test_parse (args, &argn, argc) ? 0 : 1;
 }
 
 static grub_command_t cmd_1, cmd_2;
index aa812585380025ca43ec0da56fe723fe23318657..20403c588b28bd72412e4286ee5e19fe6a405bb5 100644 (file)
@@ -34,7 +34,7 @@ grub_cmd_false (struct grub_command *cmd __attribute__ ((unused)),
                int argc __attribute__ ((unused)),
                char *argv[] __attribute__ ((unused)))
 {
-  return grub_error (GRUB_ERR_TEST_FAILURE, "false");
+  return 1;
 }
 
 static grub_command_t cmd_true, cmd_false;
index 92f14797da6f50b9d3a564d2c43ec5e6e514cfb2..442beb0d330d084c9a1631ba1b5c88485722d92f 100644 (file)
@@ -53,6 +53,9 @@ grub_script_vars1_SOURCES = tests/grub_script_vars1.in
 check_SCRIPTS += grub_script_for1
 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"
 # SCRIPTED_TESTS    = example_scripted_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_vars1
 SCRIPTED_TESTS += grub_script_for1
+SCRIPTED_TESTS += grub_script_while1
 
 # dependencies between tests and testing-tools
 $(SCRIPTED_TESTS): grub-shell grub-shell-tester
index b905de46f55a3a32fe0ee0c0449a095bb07030bd..37686627d2fa8e8e56c50ba4544ee4bf202bb4d4 100644 (file)
 #include <grub/lib/arg.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
 grub_script_execute_cmd (struct grub_script_cmd *cmd)
 {
+  int ret;
+  char errnobuf[ERRNO_DIGITS_MAX + 1];
+
   if (cmd == 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.  */
@@ -188,7 +199,6 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)
   grub_err_t ret = 0;
   int argcount = 0;
   grub_script_function_t func = 0;
-  char errnobuf[18];
   char *cmdname;
 
   /* Lookup the command.  */
@@ -222,11 +232,7 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)
              grub_env_set (assign, eq);
            }
          grub_free (assign);
-
-         grub_snprintf (errnobuf, sizeof (errnobuf), "%d", grub_errno);
-         grub_env_set ("?", errnobuf);
-
-         return 0;
+         return grub_errno;
        }
     }
 
@@ -241,9 +247,6 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)
     grub_free (args[i]);
   grub_free (args);
 
-  grub_snprintf (errnobuf, sizeof (errnobuf), "%d", ret);
-  grub_env_set ("?", errnobuf);
-
   return ret;
 }
 
@@ -251,13 +254,14 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)
 grub_err_t
 grub_script_execute_cmdblock (struct grub_script_cmd *cmd)
 {
+  int ret = 0;
   struct grub_script_cmdblock *cmdblock = (struct grub_script_cmdblock *) cmd;
 
   /* Loop over every command and execute it.  */
   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.  */