]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[cmdline] Fix up "sleep" argument parsing
authorMichael Brown <mcb30@ipxe.org>
Mon, 24 Oct 2011 14:52:14 +0000 (15:52 +0100)
committerMichael Brown <mcb30@ipxe.org>
Mon, 24 Oct 2011 14:52:14 +0000 (15:52 +0100)
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>
src/core/exec.c

index cbbccdfa4cda3827cd67d84c4d95f4feb26e4573..bcd990e099e596a28e865314bc833e368ff35f99 100644 (file)
@@ -548,17 +548,25 @@ static struct command_descriptor sleep_cmd =
  */
 static int sleep_exec ( int argc, char **argv ) {
        struct sleep_options opts;
-       unsigned long start, delay;
+       unsigned int seconds;
+       unsigned long start;
+       unsigned long delay;
        int rc;
 
        /* Parse options */
        if ( ( rc = parse_options ( argc, argv, &sleep_cmd, &opts ) ) != 0 )
                return rc;
 
+       /* Parse number of seconds */
+       if ( ( rc = parse_integer ( argv[optind], &seconds ) ) != 0 )
+               return rc;
+
+       /* Delay for specified number of seconds */
        start = currticks();
-       delay = strtoul ( argv[1], NULL, 0 ) * ticks_per_sec();
+       delay = ( seconds * TICKS_PER_SEC );
        while ( ( currticks() - start ) <= delay )
                cpu_nap();
+
        return 0;
 }