diff options
author | jkh <jkh@FreeBSD.org> | 1997-01-16 10:24:09 +0000 |
---|---|---|
committer | jkh <jkh@FreeBSD.org> | 1997-01-16 10:24:09 +0000 |
commit | b5a526ab91ac8dc6d5b040394aa64dfa85a3a940 (patch) | |
tree | a8aea9644ebcfb3ee879869a388959c83e0bee35 /release | |
parent | 4a4bd14c4c5a8bd3eadd89f2fefc58ca8315b44d (diff) | |
download | FreeBSD-src-b5a526ab91ac8dc6d5b040394aa64dfa85a3a940.zip FreeBSD-src-b5a526ab91ac8dc6d5b040394aa64dfa85a3a940.tar.gz |
Clean up a long-standing bug in the scripting code. You could set variables,
but you couldn't call functions! Now you can do both.
Guard against whitespace pollution in variable names.
Diffstat (limited to 'release')
-rw-r--r-- | release/sysinstall/dispatch.c | 28 | ||||
-rw-r--r-- | release/sysinstall/main.c | 32 | ||||
-rw-r--r-- | release/sysinstall/variable.c | 11 |
3 files changed, 44 insertions, 27 deletions
diff --git a/release/sysinstall/dispatch.c b/release/sysinstall/dispatch.c index a41a724..75f1a52 100644 --- a/release/sysinstall/dispatch.c +++ b/release/sysinstall/dispatch.c @@ -37,6 +37,8 @@ #include "sysinstall.h" #include <ctype.h> +static int _shutdown(dialogMenuItem *unused); + static struct _word { char *name; int (*handler)(dialogMenuItem *self); @@ -85,6 +87,7 @@ static struct _word { { "optionsEditor", optionsEditor }, { "addGroup", userAddGroup }, { "addUser", userAddUser }, + { "shutdown", _shutdown }, { NULL, NULL }, }; @@ -104,6 +107,13 @@ call_possible_resword(char *name, dialogMenuItem *value, int *status) return rval; } +/* Just convenience */ +static int _shutdown(dialogMenuItem *unused) +{ + systemShutdown(0); + return DITEM_FAILURE; +} + /* For a given string, call it or spit out an undefined command diagnostic */ int dispatchCommand(char *str) @@ -115,16 +125,22 @@ dispatchCommand(char *str) msgConfirm("Null or zero-length string passed to dispatchCommand"); return DITEM_FAILURE; } + /* If it's got a newline, trim it */ + if ((cp = index(str, '\n')) != NULL) + *cp = '\0'; + /* A command might be a pathname if it's encoded in argv[0], as we also support */ if (index(str, '=')) { variable_set(str); - return DITEM_SUCCESS; + i = DITEM_SUCCESS; } - else if ((cp = index(str, '/')) != NULL) - str = cp + 1; - if (!call_possible_resword(str, NULL, &i)) { - msgConfirm("No such command: %s", str); - return DITEM_FAILURE; + else { + if ((cp = index(str, '/')) != NULL) + str = cp + 1; + if (!call_possible_resword(str, NULL, &i)) { + msgConfirm("No such command: %s", str); + i = DITEM_FAILURE; + } } return i; } diff --git a/release/sysinstall/main.c b/release/sysinstall/main.c index 36b9a73..fcf9b52 100644 --- a/release/sysinstall/main.c +++ b/release/sysinstall/main.c @@ -116,21 +116,19 @@ main(int argc, char **argv) { FILE *fp; - Attribs *attrs; + char buf[BUFSIZ]; - attrs = alloca(sizeof(Attribs) * MAX_ATTRIBS); fp = fopen("install.cfg", "r"); if (fp) { msgNotify("Loading pre-configuration file"); - if (DITEM_STATUS(attr_parse(attrs, fp)) == DITEM_SUCCESS) { - int i; - - for (i = 0; attrs[i].name; i++) - variable_set2(attrs[i].name, attrs[i].value); + while (fgets(buf, sizeof buf, fp)) { + if (DITEM_STATUS(dispatchCommand(buf)) != DITEM_SUCCESS) { + msgDebug("Command `%s' failed - rest of script aborted.\n", buf); + break; + } } fclose(fp); } - #if defined(LOAD_CONFIG_FILE) else { /* If we have a compiled-in startup config file name on @@ -141,19 +139,15 @@ main(int argc, char **argv) distWanted = (char *)1; /* Try to open the floppy drive if we can do that first */ - if (DITEM_STATUS(mediaSetFloppy(NULL)) != DITEM_FAILURE && - mediaDevice->init(mediaDevice)) { - int fd; - + if (DITEM_STATUS(mediaSetFloppy(NULL)) != DITEM_FAILURE && mediaDevice->init(mediaDevice)) { fp = mediaDevice->get(mediaDevice, LOAD_CONFIG_FILE, TRUE); if (fp) { - msgNotify("Loading %s pre-configuration file", - LOAD_CONFIG_FILE); - if (DITEM_STATUS(attr_parse(attrs, fp)) == DITEM_SUCCESS) { - int i; - - for (i = 0; attrs[i].name; i++) - variable_set2(attrs[i].name, attrs[i].value); + msgNotify("Loading %s pre-configuration file", LOAD_CONFIG_FILE); + while (fgets(buf, sizeof buf, fp)) { + if (DITEM_STATUS(dispatchCommand(buf)) != DITEM_SUCCESS) { + msgDebug("Command `%s' failed - rest of script aborted.\n", buf); + break; + } } fclose(fp); } diff --git a/release/sysinstall/variable.c b/release/sysinstall/variable.c index 8ca79fc..824b0cb 100644 --- a/release/sysinstall/variable.c +++ b/release/sysinstall/variable.c @@ -42,6 +42,13 @@ static void make_variable(char *var, char *value) { Variable *vp; + char *cp; + + /* Trim leading and trailing whitespace */ + var = string_skipwhite(string_prune(var)); + + if (!var || !*var) + return; /* Put it in the environment in any case */ setenv(var, value, 1); @@ -80,7 +87,7 @@ variable_set(char *var) if ((cp = index(tmp, '=')) == NULL) msgFatal("Invalid variable format: %s", var); *(cp++) = '\0'; - make_variable(tmp, cp); + make_variable(tmp, string_skipwhite(cp)); } void @@ -108,7 +115,7 @@ variable_unset(char *var) unsetenv(var); if ((cp = index(var, '=')) != NULL) { sstrncpy(name, cp, cp - var); - var = name; + var = string_skipwhite(string_prune(name)); } /* Now search to see if it's in our list, if we have one.. */ |