Browse Source

[image] Modify imgfree command to accept an argument

This resolves potential difficulties occurring when more than one script
is used. Total cost: 88 bytes uncompressed.

Signed-off-by: Michael Brown <mcb30@etherboot.org>
tags/v0.9.8
Joshua Oreman 15 years ago
parent
commit
f8448735b0
1 changed files with 18 additions and 5 deletions
  1. 18
    5
      src/hci/commands/image_cmd.c

+ 18
- 5
src/hci/commands/image_cmd.c View File

499
  */
499
  */
500
 static void imgfree_syntax ( char **argv ) {
500
 static void imgfree_syntax ( char **argv ) {
501
 	printf ( "Usage:\n"
501
 	printf ( "Usage:\n"
502
-		 "  %s\n"
502
+		 "  %s [<image name>]\n"
503
 		 "\n"
503
 		 "\n"
504
-		 "Free all executable/loadable images\n",
504
+		 "Free one or all executable/loadable images\n",
505
 		 argv[0] );
505
 		 argv[0] );
506
 }
506
 }
507
 
507
 
519
 	};
519
 	};
520
 	struct image *image;
520
 	struct image *image;
521
 	struct image *tmp;
521
 	struct image *tmp;
522
+	const char *name = NULL;
522
 	int c;
523
 	int c;
523
 
524
 
524
 	/* Parse options */
525
 	/* Parse options */
533
 		}
534
 		}
534
 	}
535
 	}
535
 
536
 
536
-	/* No arguments */
537
+	/* Need no more than one image name */
538
+	if ( optind != argc )
539
+		name = argv[optind++];
537
 	if ( optind != argc ) {
540
 	if ( optind != argc ) {
538
 		imgfree_syntax ( argv );
541
 		imgfree_syntax ( argv );
539
 		return 1;
542
 		return 1;
540
 	}
543
 	}
541
 
544
 
542
-	/* Free all images */
543
-	list_for_each_entry_safe ( image, tmp, &images, list ) {
545
+	if ( name ) {
546
+		/* Free specified image (may leak) */
547
+		image = find_image ( name );
548
+		if ( ! image ) {
549
+			printf ( "No such image: %s\n", name );
550
+			return 1;
551
+		}
544
 		imgfree ( image );
552
 		imgfree ( image );
553
+	} else {
554
+		/* Free all images */
555
+		list_for_each_entry_safe ( image, tmp, &images, list ) {
556
+			imgfree ( image );
557
+		}
545
 	}
558
 	}
546
 	return 0;
559
 	return 0;
547
 }
560
 }

Loading…
Cancel
Save