aboutsummaryrefslogtreecommitdiffstats
path: root/com32/elflink/ldlinux
diff options
context:
space:
mode:
authorMatt Fleming <matt.fleming@linux.intel.com>2011-04-06 14:37:43 +0100
committerMatt Fleming <matt.fleming@linux.intel.com>2011-04-16 14:46:37 +0100
commit9d9b677dd1b3bf235c0ee2dd64d476fd9d85db3a (patch)
tree909a6bfa00f9de61a8ead7e12086b4c376e46573 /com32/elflink/ldlinux
parent8f9153df73881f698c83716283acf5c2bb85029d (diff)
downloadsyslinux-9d9b677dd1b3bf235c0ee2dd64d476fd9d85db3a.tar.gz
syslinux-9d9b677dd1b3bf235c0ee2dd64d476fd9d85db3a.tar.xz
syslinux-9d9b677dd1b3bf235c0ee2dd64d476fd9d85db3a.zip
ldlinux: Move cmdline processing out of cli.c
While it makes perfect sense for cli.c to read input from the user and parse certain characters (Ctrl-R, TABs, etc), once that processing is done it should be up to the caller to decide what to do with the expanded cmdline string. For example, the logic to figure out what type of kernel we're loading (calculated from a kernel's filename extension as typed on the command-line) is currently in cli.c, and that is just wrong. That kind of logic belongs in ldlinux.c So move process_command() from cli.c to ldlinux.c and extend it so that if the user types a label name at the prompt, we load the kernel for that label as described in the config file. Now that we've moved all cli history code into edit_cmdline() it seems like a good time to turn it on permanently. Signed-off-by: Matt Fleming <matt.fleming@linux.intel.com>
Diffstat (limited to 'com32/elflink/ldlinux')
-rw-r--r--com32/elflink/ldlinux/cli.c74
-rw-r--r--com32/elflink/ldlinux/ldlinux.c84
-rw-r--r--com32/elflink/ldlinux/readconfig.c2
3 files changed, 72 insertions, 88 deletions
diff --git a/com32/elflink/ldlinux/cli.c b/com32/elflink/ldlinux/cli.c
index 2f3ef29c..3026cac2 100644
--- a/com32/elflink/ldlinux/cli.c
+++ b/com32/elflink/ldlinux/cli.c
@@ -445,76 +445,14 @@ const char *edit_cmdline(const char *input, int top /*, int width */ ,
}
printf("\033[?7h");
- return ret;
-}
-
-void process_command(const char *cmd, bool history)
-{
- char **argv = malloc((MAX_COMMAND_ARGS + 1) * sizeof(char *));
- char *temp_cmd = (char *)malloc(sizeof(char) * (strlen(cmd) + 1));
- int argc = 1, len_mn;
- char *crt_arg, *module_name;
-
- /* return if user only press enter */
- if (cmd[0] == '\0') {
- printf("\n");
- return;
- }
- printf("\n");
-
- if (history) {
- struct cli_command *comm;
- comm = malloc(sizeof(struct cli_command));
- comm->command = malloc(sizeof(char) * (strlen(cmd) + 1));
- strcpy(comm->command, cmd);
- list_add(&(comm->list), &cli_history_head);
- }
-
- // dprintf("raw cmd = %s", cmd);
- strcpy(temp_cmd, cmd);
- module_name = strtok((char *)cmd, COMMAND_DELIM);
- len_mn = strlen(module_name);
-
- if (!strcmp(module_name + len_mn - 4, ".c32")) {
- if (module_find(module_name) != NULL) {
- /* make module re-enterable */
- // dprintf("Module %s is already running");
- }
- do {
- argv[0] = module_name;
- crt_arg = strtok(NULL, COMMAND_DELIM);
- if (crt_arg != NULL && strlen(crt_arg) > 0) {
- argv[argc] = crt_arg;
- argc++;
- } else
- break;
- } while (argc < MAX_COMMAND_ARGS);
- argv[argc] = NULL;
- module_load_dependencies(module_name, MODULES_DEP);
- spawn_load(module_name, (const char **)argv);
- } else if (!strcmp(module_name + len_mn - 2, ".0")) {
- execute(cmd, KT_PXE);
- } else if (!strcmp(module_name + len_mn - 3, ".bs")) {
- } else if (!strcmp(module_name + len_mn - 4, ".img")) {
- execute(cmd, KT_FDIMAGE);
- } else if (!strcmp(module_name + len_mn - 4, ".bin")) {
- } else if (!strcmp(module_name + len_mn - 4, ".bss")) {
- execute(cmd, KT_BSS);
- } else if (!strcmp(module_name + len_mn - 4, ".com")
- || !strcmp(module_name + len_mn - 4, ".cbt")) {
- execute(cmd, KT_COMBOOT);
- } else if (!strcmp(module_name + len_mn - 4, ".cfg")
- || !strcmp(module_name + len_mn - 5, ".conf")
- || !strcmp(module_name + len_mn - 7, ".config")) {
- execute(module_name, KT_CONFIG);
- }
- /* use KT_KERNEL as default */
- else
- execute(temp_cmd, KT_KERNEL);
+ /* Add the command to the history */
+ comm_counter = malloc(sizeof(struct cli_command));
+ comm_counter->command = malloc(sizeof(char) * (strlen(ret) + 1));
+ strcpy(comm_counter->command, ret);
+ list_add(&(comm_counter->list), &cli_history_head);
- free(argv);
- free(temp_cmd);
+ return ret;
}
static int cli_init(void)
diff --git a/com32/elflink/ldlinux/ldlinux.c b/com32/elflink/ldlinux/ldlinux.c
index ea889cc5..36eaded4 100644
--- a/com32/elflink/ldlinux/ldlinux.c
+++ b/com32/elflink/ldlinux/ldlinux.c
@@ -11,35 +11,60 @@
#include <sys/module.h>
-static void enter_cmdline(void)
+/*
+ * Attempt to load a kernel after deciding what type of image it is.
+ *
+ * We only return from this function if something went wrong loading
+ * the the kernel. If we return the caller should call enter_cmdline()
+ * so that the user can help us out.
+ */
+static void load_kernel(const char *kernel)
{
+ struct menu_entry *me;
+ enum kernel_type type;
const char *cmdline;
+ char *kernel_name;
+ int len;
- /* Enter endless command line prompt, should support "exit" */
- while (1) {
- cmdline = edit_cmdline("syslinux$", 1, NULL, cat_help_file);
- if (!cmdline)
- continue;
- /* feng: give up the aux check here */
- //aux = list_entry(cli_history_head.next, typeof(*aux), list);
- //if (strcmp(aux->command, cmdline)) {
- process_command(cmdline, true);
- //}
+ /* Virtual kernel? */
+ me = find_label(kernel);
+ if (me) {
+ /* XXX we don't handle LOCALBOOT yet */
+ execute(me->cmdline, KT_KERNEL);
+ /* We shouldn't return */
+ goto bad_kernel;
}
-}
-static void load_kernel(void)
-{
- enum kernel_type type;
- const char *cmdline;
+ if (!allowimplicit)
+ goto bad_implicit;
+
+ kernel_name = strtok((char *)kernel, COMMAND_DELIM);
+ len = strlen(kernel_name);
- if (defaultlevel == LEVEL_UI)
+ if (!strcmp(kernel_name + len - 4, ".c32")) {
type = KT_COM32;
+ } else if (!strcmp(kernel_name + len - 2, ".0")) {
+ type = KT_PXE;
+ } else if (!strcmp(kernel_name + len - 3, ".bs")) {
+ type = KT_BOOT;
+ } else if (!strcmp(kernel_name + len - 4, ".img")) {
+ type = KT_FDIMAGE;
+ } else if (!strcmp(kernel_name + len - 4, ".bin")) {
+ type = KT_BOOT;
+ } else if (!strcmp(kernel_name + len - 4, ".bss")) {
+ type = KT_BSS;
+ } else if (!strcmp(kernel_name + len - 4, ".com")
+ || !strcmp(kernel_name + len - 4, ".cbt")) {
+ type = KT_COMBOOT;
+ }
+ /* use KT_KERNEL as default */
else
type = KT_KERNEL;
- execute(default_cmd, type);
+ execute(kernel, type);
+bad_implicit:
+bad_kernel:
/*
* If we fail to boot the kernel execute the "onerror" command
* line.
@@ -50,6 +75,27 @@ static void load_kernel(void)
}
}
+static void enter_cmdline(void)
+{
+ const char *cmdline;
+
+ /* Enter endless command line prompt, should support "exit" */
+ while (1) {
+ cmdline = edit_cmdline("syslinux$", 1, NULL, cat_help_file);
+ if (!cmdline)
+ continue;
+
+ /* return if user only press enter */
+ if (cmdline[0] == '\0') {
+ printf("\n");
+ continue;
+ }
+ printf("\n");
+
+ load_kernel(cmdline);
+ }
+}
+
static int ldlinux_main(int argc, char **argv)
{
openconsole(&dev_rawcon_r, &dev_ansiserial_w);
@@ -67,7 +113,7 @@ static int ldlinux_main(int argc, char **argv)
*/
if (defaultlevel || noescape) {
if (defaultlevel) {
- load_kernel(); /* Shouldn't return */
+ load_kernel(default_cmd); /* Shouldn't return */
} else {
printf("No DEFAULT or UI configuration directive found!\n");
diff --git a/com32/elflink/ldlinux/readconfig.c b/com32/elflink/ldlinux/readconfig.c
index 66e84dfb..d78c0151 100644
--- a/com32/elflink/ldlinux/readconfig.c
+++ b/com32/elflink/ldlinux/readconfig.c
@@ -432,7 +432,7 @@ void print_labels(const char *prefix, size_t len)
}
}
-static struct menu_entry *find_label(const char *str)
+struct menu_entry *find_label(const char *str)
{
const char *p;
struct menu_entry *me;