]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[shell] Add "shell" command
authorMichael Brown <mcb30@ipxe.org>
Sun, 28 Nov 2010 21:09:33 +0000 (21:09 +0000)
committerMichael Brown <mcb30@ipxe.org>
Sun, 28 Nov 2010 21:09:33 +0000 (21:09 +0000)
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>
src/hci/shell.c
src/include/ipxe/shell.h

index f9cd3af28a0b7a2d236020492989b5ddd698e463..7bf138a2ece75dda1dcfab7018851e0a34ca84d2 100644 (file)
@@ -74,14 +74,57 @@ struct command help_command __command = {
  * Start command shell
  *
  */
-void shell ( void ) {
+int shell ( void ) {
        char *line;
+       int rc = 0;
 
        do {
                line = readline ( shell_prompt );
                if ( line ) {
-                       system ( line );
+                       rc = system ( line );
                        free ( line );
                }
        } while ( shell_exit == 0 );
+       shell_exit = 0;
+
+       return rc;
+}
+
+/** "shell" options */
+struct shell_options {};
+
+/** "shell" option list */
+static struct option_descriptor shell_opts[] = {};
+
+/** "shell" command descriptor */
+static struct command_descriptor shell_cmd =
+       COMMAND_DESC ( struct shell_options, shell_opts, 0, 0,
+                      "", "" );
+
+/**
+ * "shell" command
+ *
+ * @v argc             Argument count
+ * @v argv             Argument list
+ * @ret rc             Return status code
+ */
+static int shell_exec ( int argc, char **argv ) {
+       struct shell_options opts;
+       int rc;
+
+       /* Parse options */
+       if ( ( rc = parse_options ( argc, argv, &shell_cmd, &opts ) ) != 0 )
+               return rc;
+
+       /* Start shell */
+       if ( ( rc = shell() ) != 0 )
+               return rc;
+
+       return 0;
 }
+
+/** "shell" command */
+struct command shell_command __command = {
+       .name = "shell",
+       .exec = shell_exec,
+};
index 635de248bc4663f236f35d23c57057ee122d8d91..55e56346cdb639e8d30b373f50e0012189cbafa2 100644 (file)
@@ -9,6 +9,6 @@
 
 FILE_LICENCE ( GPL2_OR_LATER );
 
-extern void shell ( void );
+extern int shell ( void );
 
 #endif /* _IPXE_SHELL_H */