From a6426a4f30fe3aaa35972633c0fc0dc21e04fe18 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 29 Jun 2007 15:46:13 +0200 Subject: update the savemap upon user action or fallback When the user manually selects an entry, or when grub finds one during a fallback action, then find the first corresponding map entry and mark the next boot accordingly. --- stage2/stage2.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 49 insertions(+), 2 deletions(-) diff --git a/stage2/stage2.c b/stage2/stage2.c index a93a630..87d27d2 100644 --- a/stage2/stage2.c +++ b/stage2/stage2.c @@ -481,8 +481,26 @@ restart: if (config_entries) { + /* If the user presses Enter, he explicitly wants to set the + * current boot image to this one, which includes resetting + * the next default boot. In this case, we look for the first + * entry in the savemap for which the mapped entry matches the + * selected one. + */ if ((c == '\n') || (c == '\r') || (c == 6)) - break; + { + int i; + for (i = 0; i < MAX_SAVEMAP && savemap[i].saved != -1; i++) + { + if (savemap[i].real == first_entry + entryno) + { + default_entry = first_entry + entryno; + backup_entry = savemap[i].backup; + break; + } + } + break; + } } else { @@ -728,7 +746,24 @@ restart: /* Set CURRENT_ENTRYNO for the command "savedefault". */ current_entryno = first_entry + entryno; - + + /* check if we are booting something different from the default image. + * This may be caused by user action, of fallback because of an image + * not found. In both cases, we must update the backup image. + */ + if (current_entryno != default_entry) + { + int i; + for (i = 0; i < MAX_SAVEMAP && savemap[i].saved != -1; i++) + { + if (savemap[i].real == current_entryno) + { + default_entry = current_entryno; + backup_entry = savemap[i].backup; + break; + } + } + } if (run_script (cur_entry, heap)) { if (fallback_entryno >= 0) @@ -1042,6 +1077,18 @@ cmain (void) } else default_entry = 0; + + for (i = 0; i < MAX_SAVEMAP && savemap[i].saved != -1; i++) + { + if (savemap[i].real == default_entry) + { + default_entry = savemap[i].real; + backup_entry = savemap[i].backup; + break; + } + } + if (backup_entry >= num_entries) + backup_entry = default_entry; } if (is_preset) -- 1.4.4.3