Procházet zdrojové kódy

[time] Add the sleep command

Reviewed-by: Stefan Hajnoczi <stefanha@gmail.com>
Reviewed-by: Thomas Miletich <thomas.miletich@gmail.com>
Modified-by: Michael Brown <mcb30@etherboot.org>
Signed-off-by: Michael Brown <mcb30@etherboot.org>
tags/v0.9.8
Shao Miller před 15 roky
rodič
revize
87b494bbab
2 změnil soubory, kde provedl 31 přidání a 1 odebrání
  1. 1
    1
      src/config/general.h
  2. 30
    0
      src/hci/commands/time_cmd.c

+ 1
- 1
src/config/general.h Zobrazit soubor

@@ -101,7 +101,7 @@
101 101
 #define DHCP_CMD		/* DHCP management commands */
102 102
 #define SANBOOT_CMD		/* SAN boot commands */
103 103
 #define LOGIN_CMD		/* Login command */
104
-#undef	TIME_CMD		/* Time command */
104
+#undef	TIME_CMD		/* Time commands */
105 105
 
106 106
 /*
107 107
  * Obscure configuration options

+ 30
- 0
src/hci/commands/time_cmd.c Zobrazit soubor

@@ -14,12 +14,17 @@
14 14
  * You should have received a copy of the GNU General Public License
15 15
  * along with this program; if not, write to the Free Software
16 16
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ *
18
+ * March-19-2009 @ 02:44: Added sleep command.
19
+ * Shao Miller <shao.miller@yrdsb.edu.on.ca>.
17 20
  */
18 21
 
19 22
 #include <stdio.h>
23
+#include <stdlib.h>
20 24
 #include <string.h>
21 25
 #include <unistd.h>
22 26
 #include <gpxe/command.h>
27
+#include <gpxe/nap.h>
23 28
 #include <gpxe/timer.h>
24 29
 
25 30
 static int time_exec ( int argc, char **argv ) {
@@ -52,3 +57,28 @@ struct command time_command __command = {
52 57
 	.exec = time_exec,
53 58
 };
54 59
 
60
+static int sleep_exec ( int argc, char **argv ) {
61
+	unsigned long start, delay;
62
+
63
+	if ( argc == 1 ||
64
+	     !strcmp ( argv[1], "--help" ) ||
65
+	     !strcmp ( argv[1], "-h" ))
66
+	{
67
+		printf ( "Usage:\n"
68
+			 "  %s <seconds>\n"
69
+			 "\n"
70
+			 "Sleep for <seconds> seconds\n",
71
+			 argv[0] );
72
+		return 1;
73
+	}
74
+	start = currticks();
75
+	delay = strtoul ( argv[1], NULL, 0 ) * ticks_per_sec();
76
+	while ( ( currticks() - start ) <= delay )
77
+		cpu_nap();
78
+	return 0;
79
+}
80
+
81
+struct command sleep_command __command = {
82
+	.name = "sleep",
83
+	.exec = sleep_exec,
84
+};

Načítá se…
Zrušit
Uložit