Browse Source

[cmdline] Fix up "sleep" argument parsing

Use parse_integer() rather than strtoul() to allow parsing errors to
be reported in a meaningful way.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 years ago
parent
commit
f177a6f09f
1 changed files with 10 additions and 2 deletions
  1. 10
    2
      src/core/exec.c

+ 10
- 2
src/core/exec.c View File

548
  */
548
  */
549
 static int sleep_exec ( int argc, char **argv ) {
549
 static int sleep_exec ( int argc, char **argv ) {
550
 	struct sleep_options opts;
550
 	struct sleep_options opts;
551
-	unsigned long start, delay;
551
+	unsigned int seconds;
552
+	unsigned long start;
553
+	unsigned long delay;
552
 	int rc;
554
 	int rc;
553
 
555
 
554
 	/* Parse options */
556
 	/* Parse options */
555
 	if ( ( rc = parse_options ( argc, argv, &sleep_cmd, &opts ) ) != 0 )
557
 	if ( ( rc = parse_options ( argc, argv, &sleep_cmd, &opts ) ) != 0 )
556
 		return rc;
558
 		return rc;
557
 
559
 
560
+	/* Parse number of seconds */
561
+	if ( ( rc = parse_integer ( argv[optind], &seconds ) ) != 0 )
562
+		return rc;
563
+
564
+	/* Delay for specified number of seconds */
558
 	start = currticks();
565
 	start = currticks();
559
-	delay = strtoul ( argv[1], NULL, 0 ) * ticks_per_sec();
566
+	delay = ( seconds * TICKS_PER_SEC );
560
 	while ( ( currticks() - start ) <= delay )
567
 	while ( ( currticks() - start ) <= delay )
561
 		cpu_nap();
568
 		cpu_nap();
569
+
562
 	return 0;
570
 	return 0;
563
 }
571
 }
564
 
572
 

Loading…
Cancel
Save