Skip to content

Commit

Permalink
[image] Fail "imgexec"/"boot" if the image to execute is ambiguous
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Michael Brown committed Jul 8, 2008
1 parent 4f2861a commit 0436e41
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/hci/commands/image_cmd.c
Expand Up @@ -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;
}
}
Expand Down
14 changes: 9 additions & 5 deletions src/usr/imgmgmt.c
Expand Up @@ -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 );
}

/**
Expand Down

0 comments on commit 0436e41

Please sign in to comment.