From 0436e417bcb9acd658b73a65172474a71eb12b83 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 8 Jul 2008 03:50:44 +0100 Subject: [PATCH] [image] Fail "imgexec"/"boot" if the image to execute is ambiguous If there is more than one loaded image, refuse to automatically select the image to execute. There are at least two possible cases, with different "correct" answers: 1. User loads image A by mistake, then loads image B and types "boot". User wants to execute image B. 2. User loads image A, then loads image B (which patches image A), then types "boot". User wants to execute image A. If a user actually wants to load multiple images, they must explicitly specify which image is to be executed. --- src/hci/commands/image_cmd.c | 2 +- src/usr/imgmgmt.c | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/hci/commands/image_cmd.c b/src/hci/commands/image_cmd.c index 05e7ddeea..d1a38c470 100644 --- a/src/hci/commands/image_cmd.c +++ b/src/hci/commands/image_cmd.c @@ -407,7 +407,7 @@ static int imgexec_exec ( int argc, char **argv ) { } else { image = imgautoselect(); if ( ! image ) { - printf ( "No loaded images\n" ); + printf ( "No (unique) loaded image\n" ); return 1; } } diff --git a/src/usr/imgmgmt.c b/src/usr/imgmgmt.c index bead48678..be153f875 100644 --- a/src/usr/imgmgmt.c +++ b/src/usr/imgmgmt.c @@ -86,19 +86,23 @@ int imgexec ( struct image *image ) { } /** - * Identify the first loaded image + * Identify the only loaded image * - * @ret image Image, or NULL + * @ret image Image, or NULL if 0 or >1 images are loaded */ struct image * imgautoselect ( void ) { struct image *image; + struct image *selected_image = NULL; + int flagged_images = 0; for_each_image ( image ) { - if ( image->flags & IMAGE_LOADED ) - return image; + if ( image->flags & IMAGE_LOADED ) { + selected_image = image; + flagged_images++; + } } - return NULL; + return ( ( flagged_images == 1 ) ? selected_image : NULL ); } /**