|
|
23d2ea |
From 6d94c560ac4fa7bf0b8db3a37b414cc188fe4376 Mon Sep 17 00:00:00 2001
|
|
|
39700a |
From: Peter Jones <pjones@redhat.com>
|
|
|
39700a |
Date: Fri, 3 Oct 2014 11:08:03 -0400
|
|
|
23d2ea |
Subject: [PATCH 154/198] Try $prefix if $fw_path doesn't work.
|
|
|
39700a |
|
|
|
39700a |
Related: rhbz#1148652
|
|
|
39700a |
|
|
|
39700a |
Signed-off-by: Peter Jones <pjones@redhat.com>
|
|
|
39700a |
---
|
|
|
39700a |
grub-core/kern/ieee1275/init.c | 30 ++++++-----
|
|
|
39700a |
grub-core/net/net.c | 2 +-
|
|
|
39700a |
grub-core/normal/main.c | 118 ++++++++++++++++++++---------------------
|
|
|
39700a |
3 files changed, 75 insertions(+), 75 deletions(-)
|
|
|
39700a |
|
|
|
39700a |
diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c
|
|
|
39700a |
index 8191f8c..8ca4bf7 100644
|
|
|
39700a |
--- a/grub-core/kern/ieee1275/init.c
|
|
|
39700a |
+++ b/grub-core/kern/ieee1275/init.c
|
|
|
39700a |
@@ -131,23 +131,25 @@ grub_machine_get_bootlocation (char **device, char **path)
|
|
|
39700a |
grub_free (canon);
|
|
|
39700a |
}
|
|
|
39700a |
else
|
|
|
39700a |
- *device = grub_ieee1275_encode_devname (bootpath);
|
|
|
39700a |
- grub_free (type);
|
|
|
39700a |
-
|
|
|
39700a |
- filename = grub_ieee1275_get_filename (bootpath);
|
|
|
39700a |
- if (filename)
|
|
|
39700a |
{
|
|
|
39700a |
- char *lastslash = grub_strrchr (filename, '\\');
|
|
|
39700a |
-
|
|
|
39700a |
- /* Truncate at last directory. */
|
|
|
39700a |
- if (lastslash)
|
|
|
39700a |
+ filename = grub_ieee1275_get_filename (bootpath);
|
|
|
39700a |
+ if (filename)
|
|
|
39700a |
{
|
|
|
39700a |
- *lastslash = '\0';
|
|
|
39700a |
- grub_translate_ieee1275_path (filename);
|
|
|
39700a |
-
|
|
|
39700a |
- *path = filename;
|
|
|
39700a |
- }
|
|
|
39700a |
+ char *lastslash = grub_strrchr (filename, '\\');
|
|
|
39700a |
+
|
|
|
39700a |
+ /* Truncate at last directory. */
|
|
|
39700a |
+ if (lastslash)
|
|
|
39700a |
+ {
|
|
|
39700a |
+ *lastslash = '\0';
|
|
|
39700a |
+ grub_translate_ieee1275_path (filename);
|
|
|
39700a |
+
|
|
|
39700a |
+ *path = filename;
|
|
|
39700a |
+ }
|
|
|
39700a |
+ }
|
|
|
39700a |
+ *device = grub_ieee1275_encode_devname (bootpath);
|
|
|
39700a |
}
|
|
|
39700a |
+
|
|
|
39700a |
+ grub_free (type);
|
|
|
39700a |
grub_free (bootpath);
|
|
|
39700a |
}
|
|
|
39700a |
|
|
|
39700a |
diff --git a/grub-core/net/net.c b/grub-core/net/net.c
|
|
|
39700a |
index 578e057..10bfed3 100644
|
|
|
39700a |
--- a/grub-core/net/net.c
|
|
|
39700a |
+++ b/grub-core/net/net.c
|
|
|
39700a |
@@ -1817,7 +1817,7 @@ grub_net_search_configfile (char *config)
|
|
|
39700a |
/* Remove the remaining minus sign at the end. */
|
|
|
39700a |
config[config_len] = '\0';
|
|
|
39700a |
|
|
|
39700a |
- return GRUB_ERR_NONE;
|
|
|
39700a |
+ return GRUB_ERR_FILE_NOT_FOUND;
|
|
|
39700a |
}
|
|
|
39700a |
|
|
|
39700a |
static struct grub_preboot *fini_hnd;
|
|
|
39700a |
diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
|
|
|
39700a |
index 4190985..aa14499 100644
|
|
|
39700a |
--- a/grub-core/normal/main.c
|
|
|
39700a |
+++ b/grub-core/normal/main.c
|
|
|
39700a |
@@ -331,74 +331,72 @@ grub_enter_normal_mode (const char *config)
|
|
|
39700a |
grub_boot_time ("Exiting normal mode");
|
|
|
39700a |
}
|
|
|
39700a |
|
|
|
39700a |
+static grub_err_t
|
|
|
39700a |
+grub_try_normal (const char *variable)
|
|
|
39700a |
+{
|
|
|
39700a |
+ char *config;
|
|
|
39700a |
+ const char *prefix;
|
|
|
39700a |
+ grub_err_t err = GRUB_ERR_FILE_NOT_FOUND;
|
|
|
39700a |
+
|
|
|
39700a |
+ prefix = grub_env_get (variable);
|
|
|
39700a |
+ if (!prefix)
|
|
|
39700a |
+ return GRUB_ERR_FILE_NOT_FOUND;
|
|
|
39700a |
+
|
|
|
39700a |
+ if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0)
|
|
|
39700a |
+ {
|
|
|
39700a |
+ grub_size_t config_len;
|
|
|
39700a |
+ config_len = grub_strlen (prefix) +
|
|
|
39700a |
+ sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
|
|
|
39700a |
+ config = grub_malloc (config_len);
|
|
|
39700a |
+
|
|
|
39700a |
+ if (! config)
|
|
|
39700a |
+ return GRUB_ERR_FILE_NOT_FOUND;
|
|
|
39700a |
+
|
|
|
39700a |
+ grub_snprintf (config, config_len, "%s/grub.cfg", prefix);
|
|
|
39700a |
+ err = grub_net_search_configfile (config);
|
|
|
39700a |
+ }
|
|
|
39700a |
+
|
|
|
39700a |
+ if (err != GRUB_ERR_NONE)
|
|
|
39700a |
+ {
|
|
|
39700a |
+ config = grub_xasprintf ("%s/grub.cfg", prefix);
|
|
|
39700a |
+ if (config)
|
|
|
39700a |
+ {
|
|
|
39700a |
+ grub_file_t file;
|
|
|
39700a |
+ file = grub_file_open (config);
|
|
|
39700a |
+ if (file)
|
|
|
39700a |
+ {
|
|
|
39700a |
+ grub_file_close (file);
|
|
|
39700a |
+ err = GRUB_ERR_NONE;
|
|
|
39700a |
+ }
|
|
|
39700a |
+ }
|
|
|
39700a |
+ }
|
|
|
39700a |
+
|
|
|
39700a |
+ if (err == GRUB_ERR_NONE)
|
|
|
39700a |
+ grub_enter_normal_mode (config);
|
|
|
39700a |
+
|
|
|
39700a |
+ grub_errno = 0;
|
|
|
39700a |
+ grub_free (config);
|
|
|
39700a |
+ return err;
|
|
|
39700a |
+}
|
|
|
39700a |
+
|
|
|
39700a |
/* Enter normal mode from rescue mode. */
|
|
|
39700a |
static grub_err_t
|
|
|
39700a |
grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
|
|
|
39700a |
int argc, char *argv[])
|
|
|
39700a |
{
|
|
|
39700a |
- if (argc == 0)
|
|
|
39700a |
+ if (argc)
|
|
|
39700a |
+ grub_enter_normal_mode (argv[0]);
|
|
|
39700a |
+ else
|
|
|
39700a |
{
|
|
|
39700a |
- /* Guess the config filename. It is necessary to make CONFIG static,
|
|
|
39700a |
- so that it won't get broken by longjmp. */
|
|
|
39700a |
- char *config;
|
|
|
39700a |
- const char *prefix;
|
|
|
39700a |
-
|
|
|
39700a |
- prefix = grub_env_get ("fw_path");
|
|
|
39700a |
- if (! prefix)
|
|
|
39700a |
- prefix = grub_env_get ("prefix");
|
|
|
39700a |
-
|
|
|
39700a |
- if (prefix)
|
|
|
39700a |
- {
|
|
|
39700a |
- if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0)
|
|
|
39700a |
- {
|
|
|
39700a |
- grub_size_t config_len;
|
|
|
39700a |
- config_len = grub_strlen (prefix) +
|
|
|
39700a |
- sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
|
|
|
39700a |
- config = grub_malloc (config_len);
|
|
|
39700a |
-
|
|
|
39700a |
- if (! config)
|
|
|
39700a |
- goto quit;
|
|
|
39700a |
-
|
|
|
39700a |
- grub_snprintf (config, config_len, "%s/grub.cfg", prefix);
|
|
|
39700a |
-
|
|
|
39700a |
- grub_net_search_configfile (config);
|
|
|
39700a |
-
|
|
|
39700a |
- grub_enter_normal_mode (config);
|
|
|
39700a |
- grub_free (config);
|
|
|
39700a |
- config = NULL;
|
|
|
39700a |
- }
|
|
|
39700a |
-
|
|
|
39700a |
- if (!config)
|
|
|
39700a |
- {
|
|
|
39700a |
- config = grub_xasprintf ("%s/grub.cfg", prefix);
|
|
|
39700a |
- if (config)
|
|
|
39700a |
- {
|
|
|
39700a |
- grub_file_t file;
|
|
|
39700a |
-
|
|
|
39700a |
- file = grub_file_open (config);
|
|
|
39700a |
- if (file)
|
|
|
39700a |
- {
|
|
|
39700a |
- grub_file_close (file);
|
|
|
39700a |
- grub_enter_normal_mode (config);
|
|
|
39700a |
- }
|
|
|
39700a |
- else
|
|
|
39700a |
- {
|
|
|
39700a |
- /* Ignore all errors. */
|
|
|
39700a |
- grub_errno = 0;
|
|
|
39700a |
- }
|
|
|
39700a |
- grub_free (config);
|
|
|
39700a |
- }
|
|
|
39700a |
- }
|
|
|
39700a |
- }
|
|
|
39700a |
- else
|
|
|
39700a |
- {
|
|
|
39700a |
- grub_enter_normal_mode (0);
|
|
|
39700a |
- }
|
|
|
39700a |
+ /* Guess the config filename. */
|
|
|
39700a |
+ grub_err_t err;
|
|
|
39700a |
+ err = grub_try_normal ("fw_path");
|
|
|
39700a |
+ if (err == GRUB_ERR_FILE_NOT_FOUND)
|
|
|
39700a |
+ err = grub_try_normal ("prefix");
|
|
|
39700a |
+ if (err == GRUB_ERR_FILE_NOT_FOUND)
|
|
|
39700a |
+ grub_enter_normal_mode (0);
|
|
|
39700a |
}
|
|
|
39700a |
- else
|
|
|
39700a |
- grub_enter_normal_mode (argv[0]);
|
|
|
39700a |
|
|
|
39700a |
-quit:
|
|
|
39700a |
return 0;
|
|
|
39700a |
}
|
|
|
39700a |
|
|
|
39700a |
--
|
|
|
23d2ea |
2.7.4
|
|
|
39700a |
|