<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
<tt>With sincere apologies to all gPXE users, I got my To: list
crossed. This was meant for the developers' mailing list. - Shao<br>
<br>
Shao Miller wrote:</tt>
<blockquote type="cite" cite="mid:4B90911E.6050300@YRDSB.Edu.On.Ca">
<title>[PATCH] [script] Allow for exiting scripts</title>
<!-- Converted from text/plain format -->
<p><tt><font size="2">In staging:<br>
<a href="http://git.etherboot.org/?p=gpxe-staging.git;a=commitdiff;h=963f18ec1127b55b42434002587ac565ce33cb3a" moz-do-not-send="true">http://git.etherboot.org/?p=gpxe-staging.git;a=commitdiff;h=963f18ec1127b55b42434002587ac565ce33cb3a</a><br>
<br>
In tracking system:<br>
<a href="http://support.etherboot.org/index.php?do=details&task_id=73" moz-do-not-send="true">http://support.etherboot.org/index.php?do=details&task_id=73</a><br>
<br>
Also attached.<br>
<br>
- Shao Miller<br>
-----<br>
<br>
From 963f18ec1127b55b42434002587ac565ce33cb3a Mon Sep 17 00:00:00 2001<br>
From: Shao Miller <a href="mailto:shao.miller@yrdsb.edu.on.ca" class="moz-txt-link-rfc2396E"><shao.miller@yrdsb.edu.on.ca></a><br>
Date: Thu, 4 Mar 2010 23:14:56 -0500<br>
Subject: [PATCH] [script] Allow for exiting scripts<br>
<br>
This commit allows the 'exit' command to set a flag which the<br>
script parser will use to choose whether or not to terminate<br>
execution of a script. The flag is reset so that any calling<br>
script is not also terminated.<br>
<br>
Previously, the 'exit' command in a script did nothing. This<br>
would suggest that adding it as a new feature should not<br>
negatively impact any gPXE scripts currently in existence.<br>
<br>
For example,<br>
<br>
#!gpxe<br>
# caller.gpxe<br>
echo Caller executing<br>
imgload callee.gpxe<br>
boot callee.gpxe<br>
echo Callee must have terminated<br>
exit<br>
echo Impossibility<br>
<br>
#!gpxe<br>
# callee.gpxe<br>
echo Callee executing<br>
echo Pre-exit<br>
exit<br>
echo Post-exit<br>
<br>
$ make EMBEDDED_IMAGE=caller.gpxe,callee.gpxe bin/gpxe.pdsk<br>
$ qemu -fda bin/gpxe.pdsk -boot a<br>
<br>
Code size cost: 19 bytes uncompressed (!)<br>
---<br>
src/hci/shell.c | 8 ++++----<br>
src/image/script.c | 7 +++++++<br>
src/include/gpxe/shell.h | 1 +<br>
3 files changed, 12 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/src/hci/shell.c b/src/hci/shell.c<br>
index 5bedbdc..825dac3 100644<br>
--- a/src/hci/shell.c<br>
+++ b/src/hci/shell.c<br>
@@ -35,13 +35,13 @@ FILE_LICENCE ( GPL2_OR_LATER );<br>
static const char shell_prompt[] = "gPXE> ";<br>
<br>
/** Flag set in order to exit shell */<br>
-static int exit_flag = 0;<br>
+int shell_exit_flag = 0;<br>
<br>
/** "exit" command body */<br>
static int exit_exec ( int argc, char **argv __unused ) {<br>
<br>
if ( argc == 1 ) {<br>
- exit_flag = 1;<br>
+ shell_exit_flag = 1;<br>
} else {<br>
printf ( "Usage: exit\n"<br>
"Exits the command shell\n" );<br>
@@ -91,8 +91,8 @@ struct command help_command __command = {<br>
void shell ( void ) {<br>
char *line;<br>
<br>
- exit_flag = 0;<br>
- while ( ! exit_flag ) {<br>
+ shell_exit_flag = 0;<br>
+ while ( ! shell_exit_flag ) {<br>
line = readline ( shell_prompt );<br>
if ( line ) {<br>
system ( line );<br>
diff --git a/src/image/script.c b/src/image/script.c<br>
index 0835ecb..4073eb0 100644<br>
--- a/src/image/script.c<br>
+++ b/src/image/script.c<br>
@@ -30,6 +30,7 @@ FILE_LICENCE ( GPL2_OR_LATER );<br>
#include <ctype.h><br>
#include <errno.h><br>
#include <gpxe/image.h><br>
+#include <gpxe/shell.h><br>
<br>
struct image_type script_image_type __image_type ( PROBE_NORMAL );<br>
<br>
@@ -73,12 +74,18 @@ static int script_exec ( struct image *image ) {<br>
}<br>
}<br>
<br>
+ if ( shell_exit_flag )<br>
+ /* "exit" command should exit this script */<br>
+ goto done;<br>
/* Move to next line */<br>
offset += ( len + 1 );<br>
}<br>
<br>
rc = 0;<br>
done:<br>
+ /* Reset exit flag */<br>
+ shell_exit_flag = 0;<br>
+<br>
/* Re-register image and return */<br>
register_image ( image );<br>
return rc;<br>
diff --git a/src/include/gpxe/shell.h b/src/include/gpxe/shell.h<br>
index a65a344..148ea83 100644<br>
--- a/src/include/gpxe/shell.h<br>
+++ b/src/include/gpxe/shell.h<br>
@@ -9,6 +9,7 @@<br>
<br>
FILE_LICENCE ( GPL2_OR_LATER );<br>
<br>
+extern int shell_exit_flag;<br>
extern void shell ( void );<br>
<br>
#endif /* _GPXE_SHELL_H */<br>
--<br>
1.5.6.3<br>
<br>
</font></tt>
</p>
</blockquote>
<tt><br>
</tt>
</body>
</html>