Browse Source

[cmdline] Make "sleep" command available by default

The "sleep" command is generally useful to have.  For example:

  :dhcp_retry
  dhcp && goto dhcp_done
  sleep 5
  goto dhcp_retry
  :dhcp_done

Make the "sleep" command available by default, leaving TIME_CMD
controlling only the (fairly specialist) "time" command.

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

+ 40
- 0
src/core/exec.c View File

@@ -31,6 +31,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
31 31
 #include <ipxe/command.h>
32 32
 #include <ipxe/parseopt.h>
33 33
 #include <ipxe/settings.h>
34
+#include <ipxe/nap.h>
34 35
 #include <ipxe/shell.h>
35 36
 
36 37
 /** @file
@@ -527,3 +528,42 @@ struct command iseq_command __command = {
527 528
 	.name = "iseq",
528 529
 	.exec = iseq_exec,
529 530
 };
531
+
532
+/** "sleep" options */
533
+struct sleep_options {};
534
+
535
+/** "sleep" option list */
536
+static struct option_descriptor sleep_opts[] = {};
537
+
538
+/** "sleep" command descriptor */
539
+static struct command_descriptor sleep_cmd =
540
+	COMMAND_DESC ( struct sleep_options, sleep_opts, 1, 1, "<seconds>" );
541
+
542
+/**
543
+ * "sleep" command
544
+ *
545
+ * @v argc		Argument count
546
+ * @v argv		Argument list
547
+ * @ret rc		Return status code
548
+ */
549
+static int sleep_exec ( int argc, char **argv ) {
550
+	struct sleep_options opts;
551
+	unsigned long start, delay;
552
+	int rc;
553
+
554
+	/* Parse options */
555
+	if ( ( rc = parse_options ( argc, argv, &sleep_cmd, &opts ) ) != 0 )
556
+		return rc;
557
+
558
+	start = currticks();
559
+	delay = strtoul ( argv[1], NULL, 0 ) * ticks_per_sec();
560
+	while ( ( currticks() - start ) <= delay )
561
+		cpu_nap();
562
+	return 0;
563
+}
564
+
565
+/** "sleep" command */
566
+struct command sleep_command __command = {
567
+	.name = "sleep",
568
+	.exec = sleep_exec,
569
+};

+ 0
- 40
src/hci/commands/time_cmd.c View File

@@ -27,7 +27,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
27 27
 #include <unistd.h>
28 28
 #include <ipxe/command.h>
29 29
 #include <ipxe/parseopt.h>
30
-#include <ipxe/nap.h>
31 30
 #include <ipxe/timer.h>
32 31
 
33 32
 /** @file
@@ -78,42 +77,3 @@ struct command time_command __command = {
78 77
 	.name = "time",
79 78
 	.exec = time_exec,
80 79
 };
81
-
82
-/** "sleep" options */
83
-struct sleep_options {};
84
-
85
-/** "sleep" option list */
86
-static struct option_descriptor sleep_opts[] = {};
87
-
88
-/** "sleep" command descriptor */
89
-static struct command_descriptor sleep_cmd =
90
-	COMMAND_DESC ( struct sleep_options, sleep_opts, 1, 1, "<seconds>" );
91
-
92
-/**
93
- * "sleep" command
94
- *
95
- * @v argc		Argument count
96
- * @v argv		Argument list
97
- * @ret rc		Return status code
98
- */
99
-static int sleep_exec ( int argc, char **argv ) {
100
-	struct sleep_options opts;
101
-	unsigned long start, delay;
102
-	int rc;
103
-
104
-	/* Parse options */
105
-	if ( ( rc = parse_options ( argc, argv, &sleep_cmd, &opts ) ) != 0 )
106
-		return rc;
107
-
108
-	start = currticks();
109
-	delay = strtoul ( argv[1], NULL, 0 ) * ticks_per_sec();
110
-	while ( ( currticks() - start ) <= delay )
111
-		cpu_nap();
112
-	return 0;
113
-}
114
-
115
-/** "sleep" command */
116
-struct command sleep_command __command = {
117
-	.name = "sleep",
118
-	.exec = sleep_exec,
119
-};

Loading…
Cancel
Save