[PATCH] [script] Allow control over error handling
Shao Miller
shao.miller at yrdsb.edu.on.ca
Thu Mar 18 22:50:54 EDT 2010
Use 'clear script_errors' from within a script to prevent
any error during execution from exiting all scripts.
Use 'set script_errors 1' to restore the behaviour if it
was cleared.
Uncompressed code size cost: 97 bytes
---
src/image/script.c | 23 ++++++++++++++++++++++-
1 files changed, 22 insertions(+), 1 deletions(-)
diff --git a/src/image/script.c b/src/image/script.c
index 0835ecb..df12557 100644
--- a/src/image/script.c
+++ b/src/image/script.c
@@ -30,6 +30,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <ctype.h>
#include <errno.h>
#include <gpxe/image.h>
+#include <gpxe/settings.h>
=20
struct image_type script_image_type __image_type ( PROBE_NORMAL );
=20
@@ -44,12 +45,28 @@ static int script_exec ( struct image *image ) {
off_t eol;
size_t len;
int rc;
+ int error_control =3D 1;
+ static struct setting script_errors =3D {
+ .name =3D "script_errors",
+ .description =3D "",
+ .type =3D &setting_type_hex,
+ .tag =3D 0,
+ };
=20
/* Temporarily de-register image, so that a "boot" command
* doesn't throw us into an execution loop.
*/
unregister_image ( image );
=20
+ /* Store the current error control */
+ rc =3D store_setting ( NULL, &script_errors, &error_control,
+ sizeof ( error_control ) );
+ if ( rc < 0 ) {
+ DBG ( "Could not save script error control: %s\n",
+ strerror ( rc ) );
+ goto done;
+ }
+
while ( offset < image->len ) {
=09
/* Find length of next line, excluding any terminating
'\n' */
@@ -66,7 +83,11 @@ static int script_exec ( struct image *image ) {
copy_from_user ( cmdbuf, image->data, offset,
len );
cmdbuf[len] =3D '\0';
DBG ( "$ %s\n", cmdbuf );
- if ( ( rc =3D system ( cmdbuf ) ) !=3D 0 ) {
+ rc =3D system ( cmdbuf );
+ /* Possibly update the error control flag */
+ fetch_setting ( NULL, &script_errors,
&error_control,
+ sizeof ( error_control ) );
+ if ( rc !=3D 0 && error_control !=3D 0 ) {
DBG ( "Command \"%s\" failed: %s\n",
cmdbuf, strerror ( rc ) );
goto done;
--=20
1.5.6.3
------_=_NextPart_001_01CAC716.0B0AFF49
Content-Type: application/octet-stream;
name="script_errors.patch"
Content-Transfer-Encoding: base64
Content-Description: script_errors.patch
Content-Disposition: attachment;
filename="script_errors.patch"
RnJvbSA3OWJjYmJlNWMwN2NiNjBlZThiMjQwZWMwZmZmZjY0NDhmM2M0MmM1IE1vbiBTZXAgMTcg
MDA6MDA6MDAgMjAwMQpGcm9tOiBTaGFvIE1pbGxlciA8c2hhby5taWxsZXJAeXJkc2IuZWR1Lm9u
LmNhPgpEYXRlOiBUaHUsIDE4IE1hciAyMDEwIDIyOjUwOjU0IC0wNDAwClN1YmplY3Q6IFtQQVRD
SF0gW3NjcmlwdF0gQWxsb3cgY29udHJvbCBvdmVyIGVycm9yIGhhbmRsaW5nCgpVc2UgJ2NsZWFy
IHNjcmlwdF9lcnJvcnMnIGZyb20gd2l0aGluIGEgc2NyaXB0IHRvIHByZXZlbnQKYW55IGVycm9y
IGR1cmluZyBleGVjdXRpb24gZnJvbSBleGl0aW5nIGFsbCBzY3JpcHRzLgoKVXNlICdzZXQgc2Ny
aXB0X2Vycm9ycyAxJyB0byByZXN0b3JlIHRoZSBiZWhhdmlvdXIgaWYgaXQKd2FzIGNsZWFyZWQu
CgpVbmNvbXByZXNzZWQgY29kZSBzaXplIGNvc3Q6IDk3IGJ5dGVzCi0tLQogc3JjL2ltYWdlL3Nj
cmlwdC5jIHwgICAyMyArKysrKysrKysrKysrKysrKysrKysrLQogMSBmaWxlcyBjaGFuZ2VkLCAy
MiBpbnNlcnRpb25zKCspLCAxIGRlbGV0aW9ucygtKQoKZGlmZiAtLWdpdCBhL3NyYy9pbWFnZS9z
Y3JpcHQuYyBiL3NyYy9pbWFnZS9zY3JpcHQuYwppbmRleCAwODM1ZWNiLi5kZjEyNTU3IDEwMDY0
NAotLS0gYS9zcmMvaW1hZ2Uvc2NyaXB0LmMKKysrIGIvc3JjL2ltYWdlL3NjcmlwdC5jCkBAIC0z
MCw2ICszMCw3IEBAIEZJ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udHJvbDogJXNcbiIsCisJCSAgICAgIHN0cmVycm9y
ICggcmMgKSApOworCQlnb3RvIGRvbmU7CisJfQorCiAJd2hpbGUgKCBvZmZzZXQgPCBpbWFnZS0+
bGVuICkgewogCQogCQkvKiBGaW5kIGxlbmd0aCBvZiBuZXh0IGxpbmUsIGV4Y2x1ZGluZyBhbnkg
dGVybWluYXRpbmcgJ1xuJyAqLwpAQCAtNjYsNyArODMsMTEgQEAgc3RhdGljIGludCBzY3JpcHRf
ZXhlYyAoIHN0cnVjdCBpbWFnZSAqaW1hZ2UgKSB7CiAJCQljb3B5X2Zyb21fdXNlciAoIGNtZGJ1
ZiwgaW1hZ2UtPmRhdGEsIG9mZnNldCwgbGVuICk7CiAJCQljbWRidWZbbGVuXSA9ICdcMCc7CiAJ
CQlEQkcgKCAiJCAlc1xuIiwgY21kYnVmICk7Ci0JCQlpZiAoICggcmMgPSBzeXN0ZW0gKCBjbWRi
dWYgKSApICE9IDAgKSB7CisJCQlyYyA9IHN5c3RlbSAoIGNtZGJ1ZiApOworCQkJLyogUG9zc2li
bHkgdXBkYXRlIHRoZSBlcnJvciBjb250cm9sIGZsYWcgKi8KKwkJCWZldGNoX3NldHRpbmcgKCBO
VUxMLCAmc2NyaXB0X2Vycm9ycywgJmVycm9yX2NvbnRyb2wsCisJCQkJCXNpemVvZiAoIGVycm9y
X2NvbnRyb2wgKSApOworCQkJaWYgKCByYyAhPSAwICYmIGVycm9yX2NvbnRyb2wgIT0gMCApIHsK
IAkJCQlEQkcgKCAiQ29tbWFuZCBcIiVzXCIgZmFpbGVkOiAlc1xuIiwKIAkJCQkgICAgICBjbWRi
dWYsIHN0cmVycm9yICggcmMgKSApOwogCQkJCWdvdG8gZG9uZTsKLS0gCjEuNS42LjMKCg==
------_=_NextPart_001_01CAC716.0B0AFF49--
More information about the gPXE-devel
mailing list