update dynamic cmd dispatch with scripts support

This commit is contained in:
BVK Chaitanya 2010-07-18 20:46:21 +05:30
parent d18b05c4e3
commit f6e59c46e1
3 changed files with 50 additions and 15 deletions

View file

@ -68,10 +68,11 @@ grub_extcmd_dispatch (struct grub_command *cmd, int argc, char **args)
}
grub_extcmd_t
grub_register_extcmd (const char *name, grub_extcmd_func_t func,
unsigned flags, const char *summary,
const char *description,
const struct grub_arg_option *parser)
grub_register_extcmd_prio (const char *name, grub_extcmd_func_t func,
unsigned flags, const char *summary,
const char *description,
const struct grub_arg_option *parser,
int prio)
{
grub_extcmd_t ext;
grub_command_t cmd;
@ -81,7 +82,7 @@ grub_register_extcmd (const char *name, grub_extcmd_func_t func,
return 0;
cmd = grub_register_command_prio (name, grub_extcmd_dispatch,
summary, description, 1);
summary, description, prio);
if (! cmd)
{
grub_free (ext);
@ -99,6 +100,16 @@ grub_register_extcmd (const char *name, grub_extcmd_func_t func,
return ext;
}
grub_extcmd_t
grub_register_extcmd (const char *name, grub_extcmd_func_t func,
unsigned flags, const char *summary,
const char *description,
const struct grub_arg_option *parser)
{
return grub_register_extcmd_prio (name, func, flags,
summary, description, parser, 1);
}
void
grub_unregister_extcmd (grub_extcmd_t ext)
{

View file

@ -62,6 +62,14 @@ grub_extcmd_t grub_register_extcmd (const char *name,
const char *description,
const struct grub_arg_option *parser);
grub_extcmd_t grub_register_extcmd_prio (const char *name,
grub_extcmd_func_t func,
unsigned flags,
const char *summary,
const char *description,
const struct grub_arg_option *parser,
int prio);
void grub_unregister_extcmd (grub_extcmd_t cmd);
grub_err_t

View file

@ -23,16 +23,21 @@
#include <grub/misc.h>
#include <grub/command.h>
#include <grub/normal.h>
#include <grub/extcmd.h>
#include <grub/script_sh.h>
#include <grub/i18n.h>
static grub_err_t
grub_dyncmd_dispatcher (struct grub_command *cmd,
grub_dyncmd_dispatcher (struct grub_extcmd_context *ctxt,
int argc, char **args)
{
char *modname = cmd->data;
char *modname;
grub_dl_t mod;
grub_err_t ret;
grub_extcmd_t extcmd = ctxt->extcmd;
grub_command_t cmd = extcmd->cmd;
modname = extcmd->data;
mod = grub_dl_load (modname);
if (mod)
{
@ -42,11 +47,18 @@ grub_dyncmd_dispatcher (struct grub_command *cmd,
grub_dl_ref (mod);
name = (char *) cmd->name;
grub_unregister_command (cmd);
grub_unregister_extcmd (extcmd);
cmd = grub_command_find (name);
if (cmd)
ret = (cmd->func) (cmd, argc, args);
{
if (cmd->flags & GRUB_COMMAND_FLAG_BLOCKS &&
cmd->flags & GRUB_COMMAND_FLAG_EXTCMD)
ret = grub_extcmd_dispatcher (cmd, argc, args,
ctxt->script_params);
else
ret = (cmd->func) (cmd, argc, args);
}
else
ret = grub_errno;
@ -81,13 +93,14 @@ read_command_list (const char *prefix)
for (ptr = grub_command_list; ptr; ptr = next)
{
next = ptr->next;
if (ptr->func == grub_dyncmd_dispatcher)
if (ptr->flags & GRUB_COMMAND_FLAG_DYNCMD)
{
if (last)
last->next = ptr->next;
else
grub_command_list = ptr->next;
grub_free (ptr);
grub_free (ptr->data); /* extcmd struct */
}
else
last = ptr;
@ -96,7 +109,7 @@ read_command_list (const char *prefix)
for (;; grub_free (buf))
{
char *p, *name, *modname;
grub_command_t cmd;
grub_extcmd_t cmd;
int prio = 0;
buf = grub_file_getline (file);
@ -139,16 +152,19 @@ read_command_list (const char *prefix)
continue;
}
cmd = grub_register_command_prio (name,
grub_dyncmd_dispatcher,
0, N_("not loaded"), prio);
cmd = grub_register_extcmd_prio (name,
grub_dyncmd_dispatcher,
GRUB_COMMAND_FLAG_BLOCKS
| GRUB_COMMAND_FLAG_EXTCMD
| GRUB_COMMAND_FLAG_DYNCMD,
0, N_("not loaded"), 0,
prio);
if (! cmd)
{
grub_free (name);
grub_free (modname);
continue;
}
cmd->flags |= GRUB_COMMAND_FLAG_DYNCMD;
cmd->data = modname;
/* Update the active flag. */