Pārlūkot izejas kodu

[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 gadus atpakaļ
vecāks
revīzija
f177a6f09f
1 mainītis faili ar 10 papildinājumiem un 2 dzēšanām
  1. 10
    2
      src/core/exec.c

+ 10
- 2
src/core/exec.c Parādīt failu

@@ -548,17 +548,25 @@ static struct command_descriptor sleep_cmd =
548 548
  */
549 549
 static int sleep_exec ( int argc, char **argv ) {
550 550
 	struct sleep_options opts;
551
-	unsigned long start, delay;
551
+	unsigned int seconds;
552
+	unsigned long start;
553
+	unsigned long delay;
552 554
 	int rc;
553 555
 
554 556
 	/* Parse options */
555 557
 	if ( ( rc = parse_options ( argc, argv, &sleep_cmd, &opts ) ) != 0 )
556 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 565
 	start = currticks();
559
-	delay = strtoul ( argv[1], NULL, 0 ) * ticks_per_sec();
566
+	delay = ( seconds * TICKS_PER_SEC );
560 567
 	while ( ( currticks() - start ) <= delay )
561 568
 		cpu_nap();
569
+
562 570
 	return 0;
563 571
 }
564 572
 

Notiek ielāde…
Atcelt
Saglabāt