]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
2005-08-14 Yoshinori K. Okuji <okuji@enbug.org>
authorokuji <okuji@localhost>
Sun, 14 Aug 2005 19:36:55 +0000 (19:36 +0000)
committerokuji <okuji@localhost>
Sun, 14 Aug 2005 19:36:55 +0000 (19:36 +0000)
        * normal/menu.c (run_menu_entry):

        * normal/command.c (grub_command_execute): If INTERACTIVE is
        false and GRUB_COMMAND_FLAG_NO_ECHO is not specified, print
        CMDLINE. Disable the pager if INTERACTIVE is true.
        All callers are changed.

        * normal/main.c (grub_normal_execute): Read command.lst and fs.lst
        before reading a config file.
        * normal/main.c (read_config_file): Even if a command is not
        found, register it if it is within an entry.

        * util/grub-emu.c: Include sys/types.h and unistd.h.
        (options): Added --hold.
        (struct arguments): Added a new member "hold".
        (parse_opt): If KEY is 'H', set ARGS->HOLD to ARG or -1 if ARG is
        missing.
        (main): Initialize ARGS.HOLD to zero. Wait until ARGS.HOLD is
        cleared by a debugger, if it is not zero.

        * include/grub/normal.h (grub_command_execute): Add an argument
        INTERACTIVE.

ChangeLog
include/grub/normal.h
normal/cmdline.c
normal/command.c
normal/main.c
normal/menu.c
normal/menu_entry.c
util/grub-emu.c

index 474487ee2a9df5850454333bd55e905eba829328..478a3343518bdb3e3af76381f3836643955df292 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2005-08-14  Yoshinori K. Okuji  <okuji@enbug.org>
+
+       * normal/menu.c (run_menu_entry): 
+
+       * normal/command.c (grub_command_execute): If INTERACTIVE is
+       false and GRUB_COMMAND_FLAG_NO_ECHO is not specified, print
+       CMDLINE. Disable the pager if INTERACTIVE is true.
+       All callers are changed.
+
+       * normal/main.c (grub_normal_execute): Read command.lst and fs.lst
+       before reading a config file.
+       * normal/main.c (read_config_file): Even if a command is not
+       found, register it if it is within an entry.
+
+       * util/grub-emu.c: Include sys/types.h and unistd.h.
+       (options): Added --hold.
+       (struct arguments): Added a new member "hold".
+       (parse_opt): If KEY is 'H', set ARGS->HOLD to ARG or -1 if ARG is
+       missing.
+       (main): Initialize ARGS.HOLD to zero. Wait until ARGS.HOLD is
+       cleared by a debugger, if it is not zero.
+
+       * include/grub/normal.h (grub_command_execute): Add an argument
+       INTERACTIVE.
+
 2005-08-14  Vesa Jaaskelainen  <chaac@nic.fi>
 
        * DISTLIST: Added include/grub/i386/pc/vbe.h.
index 04926b94027da76e919403e261d656dff242f561..b890040000a76684a16decf736acc7c69e4fc784 100644 (file)
@@ -167,7 +167,7 @@ void grub_unregister_command (const char *name);
 grub_command_t grub_command_find (char *cmdline);
 grub_err_t grub_set_history (int newsize);
 int grub_iterate_commands (int (*iterate) (grub_command_t));
-int grub_command_execute (char *cmdline);
+int grub_command_execute (char *cmdline, int interactive);
 void grub_command_init (void);
 void grub_normal_init_page (void);
 void grub_menu_init_page (int nested, int edit);
index c74a2703804ab670be45dacc820661f70fa284de..b8475474fe640ffa2a3b320c61fea78d2a77bf1c 100644 (file)
@@ -160,7 +160,7 @@ grub_cmdline_run (int nested)
       if (! *cmdline)
        continue;
 
-      grub_command_execute (cmdline);
+      grub_command_execute (cmdline, 1);
     }
 }
 
index 919734852267122220899b8ab34309c0bcafd24c..6a2d364cc316b98a85a416d969a249f98205c973 100644 (file)
@@ -182,7 +182,7 @@ grub_iterate_commands (int (*iterate) (grub_command_t))
 }
 
 int
-grub_command_execute (char *cmdline)
+grub_command_execute (char *cmdline, int interactive)
 {
   auto grub_err_t cmdline_get (char **s);
   grub_err_t cmdline_get (char **s)
@@ -210,7 +210,12 @@ grub_command_execute (char *cmdline)
      of calling a function.  */
   if (num == 0 && grub_strchr (args[0], '='))
     {
-      char *val = grub_strchr (args[0], '=');
+      char *val;
+
+      if (! interactive)
+       grub_printf ("%s\n", cmdline);
+      
+      val = grub_strchr (args[0], '=');
       val[0] = 0;
       grub_env_set (args[0], val + 1);
       val[0] = '=';
@@ -221,8 +226,14 @@ grub_command_execute (char *cmdline)
   if (! cmd)
     return -1;
 
+  if (! (cmd->flags & GRUB_COMMAND_FLAG_NO_ECHO) && ! interactive)
+    grub_printf ("%s\n", cmdline);
+  
   /* Enable the pager if the environment pager is set to 1.  */
-  pager = grub_env_get ("pager");
+  if (interactive)
+    pager = grub_env_get ("pager");
+  else
+    pager = 0;
   if (pager && (! grub_strcmp (pager, "1")))
     grub_set_more (1);
   
index 2a39ce54f1540c582e81f04536bc53e00b9c1bb5..7ab178102aa50736c1b630c19ab71de7319cbdbf 100644 (file)
@@ -178,9 +178,35 @@ read_config_file (const char *config)
   while (get_line (file, cmdline, sizeof (cmdline)))
     {
       grub_command_t cmd;
-      
+
       cmd = grub_command_find (cmdline);
       grub_errno = GRUB_ERR_NONE;
+      
+      if (cur_entry)
+       {
+         if (! cmd || ! (cmd->flags & GRUB_COMMAND_FLAG_TITLE))
+           {
+             cur_cmd = (grub_command_list_t) grub_malloc (sizeof (*cur_cmd));
+             if (! cur_cmd)
+               goto fail;
+             
+             cur_cmd->command = grub_strdup (cmdline);
+             if (! cur_cmd->command)
+               {
+                 grub_free (cur_cmd);
+                 goto fail;
+               }
+             
+             cur_cmd->next = 0;
+             
+             *next_cmd = cur_cmd;
+             next_cmd = &(cur_cmd->next);
+             
+             cur_entry->num++;
+             continue;
+           }
+       }
+      
       if (! cmd)
        {
          grub_printf ("Unknown command `%s' is ignored.\n", cmdline);
@@ -218,12 +244,12 @@ read_config_file (const char *config)
          
          menu->size++;
        }
-      else if (! cur_entry)
+      else
        {
          /* Run the command if possible.  */
          if (cmd->flags & GRUB_COMMAND_FLAG_MENU)
            {
-             grub_command_execute (cmdline);
+             grub_command_execute (cmdline, 0);
              if (grub_errno != GRUB_ERR_NONE)
                {
                  grub_print_error ();
@@ -236,26 +262,6 @@ read_config_file (const char *config)
              continue;
            }
        }
-      else
-       {
-         cur_cmd = (grub_command_list_t) grub_malloc (sizeof (*cur_cmd));
-         if (! cur_cmd)
-           goto fail;
-
-         cur_cmd->command = grub_strdup (cmdline);
-         if (! cur_cmd->command)
-           {
-             grub_free (cur_cmd);
-             goto fail;
-           }
-
-         cur_cmd->next = 0;
-         
-         *next_cmd = cur_cmd;
-         next_cmd = &(cur_cmd->next);
-         
-         cur_entry->num++;
-       }
     }
 
  fail:
@@ -463,6 +469,9 @@ grub_normal_execute (const char *config, int nested)
 {
   grub_menu_t menu = 0;
 
+  read_command_list ();
+  read_fs_list ();
+  
   if (config)
     {
       menu = read_config_file (config);
@@ -471,9 +480,6 @@ grub_normal_execute (const char *config, int nested)
       grub_errno = GRUB_ERR_NONE;
     }
 
-  read_command_list ();
-  read_fs_list ();
-  
   if (menu)
     {
       grub_menu_run (menu, nested);
index 4265cd3a09686a0fcb852a66069963be9fe52f5c..8fc755c63c37c2268a8edd5044ab7f04c604c3ad 100644 (file)
@@ -319,34 +319,17 @@ run_menu_entry (grub_menu_entry_t entry)
 
   for (cl = entry->command_list; cl != 0; cl = cl->next)
     {
-      grub_command_t c;
-
       if (cl->command[0] == '\0')
        /* Ignore an empty command line.  */
        continue;
       
-      c = grub_command_find (cl->command);
-      if (! c)
-       break;
-      
-      if (! (c->flags & GRUB_COMMAND_FLAG_CMDLINE))
-       {
-         grub_error (GRUB_ERR_INVALID_COMMAND,
-                     "invalid command `%s'",
-                     cl->command);
-         break;
-       }
-      
-      if (! (c->flags & GRUB_COMMAND_FLAG_NO_ECHO))
-       grub_printf ("%s\n", cl->command);
-      
-      if (grub_command_execute (cl->command) != 0)
+      if (grub_command_execute (cl->command, 0) != 0)
        break;
     }
   
   if (grub_errno == GRUB_ERR_NONE && grub_loader_is_loaded ())
     /* Implicit execution of boot, only if something is loaded.  */
-    grub_command_execute ("boot");
+    grub_command_execute ("boot", 0);
 }
 
 void
index 5b11ed90f9de9a8d9072207272816f933d12dc78..81ff8fe12985b418726634881307573bc21c8e1d 100644 (file)
@@ -822,7 +822,6 @@ run (struct screen *screen)
     {
       struct line *linep = screen->lines + i;
       char *p;
-      grub_command_t c;
       
       /* Trim down space characters.  */
       for (p = linep->buf + linep->len - 1;
@@ -839,26 +838,13 @@ run (struct screen *screen)
        /* Ignore an empty command line.  */
        continue;
 
-      c = grub_command_find (p);
-      if (! c)
-       break;
-      
-      if (! (c->flags & GRUB_COMMAND_FLAG_CMDLINE))
-       {
-         grub_error (GRUB_ERR_INVALID_COMMAND, "invalid command `%s'", p);
-         break;
-       }
-      
-      if (! (c->flags & GRUB_COMMAND_FLAG_NO_ECHO))
-       grub_printf ("%s\n", p);
-      
-      if (grub_command_execute (p) != 0)
+      if (grub_command_execute (p, 0) != 0)
        break;
     }
   
   if (grub_errno == GRUB_ERR_NONE && grub_loader_is_loaded ())
     /* Implicit execution of boot, only if something is loaded.  */
-    grub_command_execute ("boot");
+    grub_command_execute ("boot", 0);
 
   if (grub_errno != GRUB_ERR_NONE)
     {
index e57fe3b964297a0b43ee7571c8d50829fda98791..7bf07877bc4229189403f29b15db92ae2fea30e3 100644 (file)
@@ -23,6 +23,8 @@
 #include <argp.h>
 #include <string.h>
 #include <signal.h>
+#include <sys/types.h>
+#include <unistd.h>
 
 #include <grub/mm.h>
 #include <grub/setjmp.h>
@@ -95,6 +97,7 @@ static struct argp_option options[] = {
   {"device-map",  'm', "FILE", 0, "use FILE as the device map", 0},
   {"directory",   'd', "DIR",  0, "use GRUB files in the directory DIR", 0},
   {"verbose",     'v', 0     , 0, "print verbose messages", 0},
+  {"hold",        'H', "SECONDS", OPTION_ARG_OPTIONAL, "wait until a debugger will attach", 0},
   { 0, 0, 0, 0, 0, 0 }
 };
 
@@ -103,6 +106,7 @@ struct arguments
   char *root_dev;
   char *dev_map;
   char *dir;
+  int hold;
 };
 
 static error_t
@@ -124,6 +128,9 @@ parse_opt (int key, char *arg, struct argp_state *state)
     case 'v':
       verbosity++;
       break;
+    case 'H':
+      args->hold = arg ? atoi (arg) : -1;
+      break;
     case ARGP_KEY_END:
       break;
     default:
@@ -143,13 +150,26 @@ main (int argc, char *argv[])
   struct arguments args =
     {
       .dir = DEFAULT_DIRECTORY,
-      .dev_map = DEFAULT_DEVICE_MAP
+      .dev_map = DEFAULT_DEVICE_MAP,
+      .hold = 0
     };
   
   progname = "grub-emu";
   
   argp_parse (&argp, argc, argv, 0, 0, &args);
 
+  /* Wait until the ARGS.HOLD variable is cleared by an attached debugger. */
+  if (args.hold && verbosity > 0)
+    printf ("Run \"gdb %s %d\", and set ARGS.HOLD to zero.\n",
+            progname, (int) getpid ());
+  while (args.hold)
+    {
+      if (args.hold > 0)
+        args.hold--;
+
+      sleep (1);
+    }
+  
   /* Make sure that there is a root device.  */
   if (! args.root_dev)
     {