summaryrefslogtreecommitdiffstats
path: root/src/core/exec.c
diff options
context:
space:
mode:
authorMichael Brown2011-10-24 16:52:14 +0200
committerMichael Brown2011-10-24 16:52:14 +0200
commitf177a6f09ff5d702fd01619e0db05e92a99976d7 (patch)
treeef2ace81118c4563e8ec57ca25cfe8d6db9df588 /src/core/exec.c
parent[cmdline] Make "sleep" command available by default (diff)
downloadipxe-f177a6f09ff5d702fd01619e0db05e92a99976d7.tar.gz
ipxe-f177a6f09ff5d702fd01619e0db05e92a99976d7.tar.xz
ipxe-f177a6f09ff5d702fd01619e0db05e92a99976d7.zip
[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>
Diffstat (limited to 'src/core/exec.c')
-rw-r--r--src/core/exec.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/core/exec.c b/src/core/exec.c
index cbbccdfa..bcd990e0 100644
--- a/src/core/exec.c
+++ b/src/core/exec.c
@@ -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;
}