Browse Source

[shell] Add "shell" command

The "shell" command allows a script to enter an interactive shell,
which is potentially useful for troubleshooting.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 14 years ago
parent
commit
1fcea25c42
2 changed files with 46 additions and 3 deletions
  1. 45
    2
      src/hci/shell.c
  2. 1
    1
      src/include/ipxe/shell.h

+ 45
- 2
src/hci/shell.c View File

@@ -74,14 +74,57 @@ struct command help_command __command = {
74 74
  * Start command shell
75 75
  *
76 76
  */
77
-void shell ( void ) {
77
+int shell ( void ) {
78 78
 	char *line;
79
+	int rc = 0;
79 80
 
80 81
 	do {
81 82
 		line = readline ( shell_prompt );
82 83
 		if ( line ) {
83
-			system ( line );
84
+			rc = system ( line );
84 85
 			free ( line );
85 86
 		}
86 87
 	} while ( shell_exit == 0 );
88
+	shell_exit = 0;
89
+
90
+	return rc;
91
+}
92
+
93
+/** "shell" options */
94
+struct shell_options {};
95
+
96
+/** "shell" option list */
97
+static struct option_descriptor shell_opts[] = {};
98
+
99
+/** "shell" command descriptor */
100
+static struct command_descriptor shell_cmd =
101
+	COMMAND_DESC ( struct shell_options, shell_opts, 0, 0,
102
+		       "", "" );
103
+
104
+/**
105
+ * "shell" command
106
+ *
107
+ * @v argc		Argument count
108
+ * @v argv		Argument list
109
+ * @ret rc		Return status code
110
+ */
111
+static int shell_exec ( int argc, char **argv ) {
112
+	struct shell_options opts;
113
+	int rc;
114
+
115
+	/* Parse options */
116
+	if ( ( rc = parse_options ( argc, argv, &shell_cmd, &opts ) ) != 0 )
117
+		return rc;
118
+
119
+	/* Start shell */
120
+	if ( ( rc = shell() ) != 0 )
121
+		return rc;
122
+
123
+	return 0;
87 124
 }
125
+
126
+/** "shell" command */
127
+struct command shell_command __command = {
128
+	.name = "shell",
129
+	.exec = shell_exec,
130
+};

+ 1
- 1
src/include/ipxe/shell.h View File

@@ -9,6 +9,6 @@
9 9
 
10 10
 FILE_LICENCE ( GPL2_OR_LATER );
11 11
 
12
-extern void shell ( void );
12
+extern int shell ( void );
13 13
 
14 14
 #endif /* _IPXE_SHELL_H */

Loading…
Cancel
Save