From d3c660b6718c8d85b34d5c7ca8c4ed12659e1cc7 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Fri, 20 Jul 2012 10:37:24 +0100 Subject: [image] Add "--autofree" option Allow images to be automatically freed after execution completes (successfully or otherwise). Signed-off-by: Michael Brown --- src/hci/commands/image_cmd.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/hci/commands/image_cmd.c') diff --git a/src/hci/commands/image_cmd.c b/src/hci/commands/image_cmd.c index 1ae33074..38d814cd 100644 --- a/src/hci/commands/image_cmd.c +++ b/src/hci/commands/image_cmd.c @@ -38,19 +38,24 @@ FILE_LICENCE ( GPL2_OR_LATER ); struct imgsingle_options { /** Image name */ const char *name; + /** Free image after execution */ + int autofree; }; /** "img{single}" option list */ static struct option_descriptor imgsingle_opts[] = { OPTION_DESC ( "name", 'n', required_argument, struct imgsingle_options, name, parse_string ), + OPTION_DESC ( "autofree", 'a', no_argument, + struct imgsingle_options, autofree, parse_flag ), }; /** "img{single}" command descriptor */ static struct command_descriptor imgsingle_cmd = COMMAND_DESC ( struct imgsingle_options, imgsingle_opts, 1, MAX_ARGUMENTS, - "[--name ] [...]" ); + "[--name ] [--autofree] " + " [...]" ); /** An "img{single}" family command descriptor */ struct imgsingle_descriptor { @@ -134,6 +139,10 @@ static int imgsingle_exec ( int argc, char **argv, } } + /* Set the auto-unregister flag, if applicable */ + if ( opts.autofree ) + image->flags |= IMAGE_AUTO_UNREGISTER; + /* Carry out command action, if applicable */ if ( desc->action ) { if ( ( rc = desc->action ( image ) ) != 0 ) { @@ -160,7 +169,7 @@ static int imgsingle_exec ( int argc, char **argv, static struct command_descriptor imgfetch_cmd = COMMAND_DESC ( struct imgsingle_options, imgsingle_opts, 1, MAX_ARGUMENTS, - "[--name ] [...]" ); + "[--name ] [--autofree] [...]" ); /** "imgfetch" family command descriptor */ struct imgsingle_descriptor imgfetch_desc = { @@ -202,7 +211,7 @@ static int imgselect_exec ( int argc, char **argv ) { static struct command_descriptor imgexec_cmd = COMMAND_DESC ( struct imgsingle_options, imgsingle_opts, 0, MAX_ARGUMENTS, - "[--name ] [ [...]]" ); + "[--autofree] [ [...]]" ); /** "imgexec" family command descriptor */ struct imgsingle_descriptor imgexec_desc = { -- cgit v1.2.3-55-g7522