diff options
author | Michael Brown | 2011-03-28 19:48:48 +0200 |
---|---|---|
committer | Michael Brown | 2011-03-28 19:50:27 +0200 |
commit | 2f6e7bde772205726369b4d0a98a01f3e0b06c16 (patch) | |
tree | 6d11a2f15489815234ecfd26f6e02097398b4bad /src/core/main.c | |
parent | [cmdline] Expand settings within each command-line token individually (diff) | |
download | ipxe-2f6e7bde772205726369b4d0a98a01f3e0b06c16.tar.gz ipxe-2f6e7bde772205726369b4d0a98a01f3e0b06c16.tar.xz ipxe-2f6e7bde772205726369b4d0a98a01f3e0b06c16.zip |
[main] Add the "scriptlet" setting
A scriptlet is a single iPXE command that can be stored in
non-volatile option storage and used to override the default
"autoboot" behaviour without having to reflash the iPXE image.
For example, a scriptlet could contain
autoboot || reboot
to instruct iPXE to reboot the system if booting fails.
Unlike an embedded image, the presence of a scriptlet does not inhibit
the initial "Press Ctrl-B..." prompt. This allows the user to recover
from setting a faulty scriptlet.
Originally-implemented-by: Glenn Brown <glenn@myri.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core/main.c')
-rw-r--r-- | src/core/main.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/core/main.c b/src/core/main.c index aac27e9b..9fd4a76f 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -15,6 +15,7 @@ Literature dealing with the network protocols: FILE_LICENCE ( GPL2_OR_LATER ); #include <stdio.h> +#include <stdlib.h> #include <ipxe/init.h> #include <ipxe/features.h> #include <ipxe/shell.h> @@ -28,6 +29,14 @@ FILE_LICENCE ( GPL2_OR_LATER ); #define BOLD "\033[1m" #define CYAN "\033[36m" +/** The "scriptlet" setting */ +struct setting scriptlet_setting __setting ( SETTING_MISC ) = { + .name = "scriptlet", + .description = "Boot scriptlet", + .tag = DHCP_EB_SCRIPTLET, + .type = &setting_type_string, +}; + /** * Prompt for shell entry * @@ -51,6 +60,7 @@ static int shell_banner ( void ) { __asmcall int main ( void ) { struct feature *feature; struct image *image; + char *scriptlet; /* Some devices take an unreasonably long time to initialise */ printf ( PRODUCT_SHORT_NAME " initialising devices..." ); @@ -82,11 +92,16 @@ __asmcall int main ( void ) { if ( ( image = first_image() ) != NULL ) { /* We have an embedded image; execute it */ image_exec ( image ); + } else if ( shell_banner() ) { + /* User wants shell; just give them a shell */ + shell(); } else { - /* Prompt for shell */ - if ( shell_banner() ) { - /* User wants shell; just give them a shell */ - shell(); + fetch_string_setting_copy ( NULL, &scriptlet_setting, + &scriptlet ); + if ( scriptlet ) { + /* User has defined a scriptlet; execute it */ + system ( scriptlet ); + free ( scriptlet ); } else { /* Try booting. If booting fails, offer the * user another chance to enter the shell. |