summaryrefslogtreecommitdiffstats
path: root/discover/grub2
Commit message (Collapse)AuthorAgeFilesLines
* discover/grub: Fix handling of empty stringsSam Mendoza-Jonas2016-02-091-0/+7
| | | | | | | | | | | If "" or '' are used in a statement to omit a word, we must still return a TOKEN_WORD for an empty string. In particular this fixes an issue where Petitboot would fail to parse the grub.cfg included in the Debian 8.2 install image, which includes a menuentry statement with an empty name. Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
* discover/grub2: Fix behavior of save_env -fAlan Dunn2016-02-081-3/+14
| | | | | | | | | | | | | | | Currently, "save_env -f" in the GRUB2 parser only works with three arguments, which means only commands of the form "save_env -f <path>" that save *no* environment variables are allowed. Allow "save_env -f <path> [<var>]*", making "save_env -f" useful. Tested: Unit test test-grub2-save-env-dash-f tests this change, and the remaining unit tests still pass. Signed-off-by: Alan Dunn <amdunn@google.com> Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
* discover: Initialise strtok_r saveptr to NULLSamuel Mendoza-Jonas2015-04-141-1/+1
| | | | | Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Allow unset and invalid defaultsJeremy Kerr2014-12-112-1/+35
| | | | | | | | | | | | | | If the default environment variable is unset or invalid (i.e., references a non-existent boot option), then GRUB2 will fallback to the first boot option present. This is preventing petitboot from autobooting where no default is explicitly set, or is stale. This change adds this fallback behaviour to petitboot. Because we don't know if the first option will be a default at parse time (as no other options matched the default env var), we need to keep options in a list, and register them with the discover server once the parse is complete. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: improve handling of word & delimiter tokensJeremy Kerr2014-12-013-41/+57
| | | | | | | | | | | | | | | | | | | | | | | Currently, the delimiter token handling is a little fragile: we try to ignore non-inter-word delimiters in the lexer with a selective set of regexes on the possible delimiter characters. This means we don't need to handle potential delimiters in every grammar rule, but there are other situations (not regex-able) where we may see delimters, and this will cause a parse error. Instead of relying on the regex behaviour, we have an 'inter_word' flag, which is set when we see the first word token, and cleared when we see an end-of-line token. We only emit TOKEN_DELIM when this flag is set. This means that we only get the delim tokens when they're required - when we're looking for word separators (becuase WORD DELIM WORD is distinct from WORD WORD - eg "linux /vmlinux" and "x$var"). We add a few new tests for the "menuentry" and "if" syntax, with different delimiter configurations. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: fix incorrect prototype in yyerrorJeremy Kerr2014-12-012-5/+6
| | | | | | | Because we're using two parse-params, we need to add the scanner argument to yyerror. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* lib: Move generic file-handling code to lib/Jeremy Kerr2014-08-051-1/+1
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: distinguish parser.h from grub2/parser.hJeremy Kerr2014-08-053-18/+18
| | | | | | | | | | | | | 'make distcheck' will do a 'make all' srcdir == objdir, then later a 'make check' sith srcdir != objdir. Since gcc's cpp always assumes that a source file's directory is first in the include paths, we may see discover/parser.h included when we wanted the generated discover/grub2/parser.h. This change renames the grub2 lexer and parser files, to work-around this behaviour, and fix 'make distcheck'. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* automake: silence make outputJeremy Kerr2014-08-051-5/+2
| | | | | | | | | Currently, we get a lot of noise out of the build process; automake supports V={0,1}, which we can use to suppress the output a little. This needs a few cleanups for custom commands. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* autotools: Use non-recursive makeJeremy Kerr2014-08-012-28/+36
| | | | | | | | | | | | With the current testing infrastructure, we don't have a strictly hierarchical set of dependencies. This causes problems with a recursive make, and means we have to hack around some of the dependencies. This change generates a single, top-level makefile from all of the Makefile.am fragments. We still need the po/ directory as a separate SUBDIR, but all others can be converted to non-recursive. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* grub2: fix empty file handlingJeremy Kerr2014-06-051-0/+3
| | | | | | | | | | | Currently, we have a bug when parsing zero-length files: we subtract one from the length to exclude the trailing NUL (added by read_file), but a zero-length file will result in a length of -1. This change adds an explicit exit if we're attempting to parse an empty file. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Fix uninitialised var warningsJeremy Kerr2014-04-161-1/+1
| | | | | | | | | | | | | | We get a couple of uninitialised var warning when compiling with certain CFLAGS (-fprofile-arcs -ftest-coverage at this stage). In statement_if_execute: We'll never actually use this uninitialised (as there must be at least one conditional in the parsed statement), but we should address the warning nonetheless. As passed to strtok_r: strtok will initialise this, but it isn't obvious to the compiler. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Add support for for-loopsJeremy Kerr2014-01-303-0/+55
| | | | | | | | | GRUB2 syntax allows for for-loops; this change adds supoprt in the parser grammar and script execution code to implement them. In the execution code, we simply update the for-loop variable and re-execute the body statements. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Perform word-expansion non-destructivelyJeremy Kerr2014-01-301-99/+83
| | | | | | | | | | | | | | | In order to implement for-loops, we may need to evaluate the same chunk of script more than once, and perform that evaluation in a different context (particularly, with different environment variables). Currently, the process_expansion code destroys the result of the parse-tree (ie, the token list) when performing expansions. This means that we can only perform the expansions once. This change preserves the token list while creating the argv array. This means that we can expand the list multiple times. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Add support for checking directories in parser APIJeremy Kerr2014-01-301-0/+14
| | | | | | | | | | | | | This change adds a function to the parser API: int parser_check_dir(struct discover_context *ctx, struct discover_device *dev, const char *dirname) - which allows parsers to check for the presence of a directory (path of 'dirname') on the device ('dev'). We use this in the GRUB2 parser to implement the `test -d` check. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: skip menuentries that don't define a boot optionJeremy Kerr2014-01-301-0/+3
| | | | | | | | | | menuentries may perform arbitrary commands; we only want ones that define a boot option. This change doesn't add a boot option if we haven't seen at least a boot image defined in the menuentry. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub: Add feature variable for --id support.Jeremy Kerr2014-01-301-0/+3
| | | | | | | Since we support --id arguments on menuentries, add the corresponding feature variable. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Use script_env_set when initialising the environmentJeremy Kerr2014-01-301-6/+2
| | | | | | | | | | No need to duplicate the environment-adding code in init_env, as we can just use script_env_set. Since script_env_set does its own talloc, we don't need to talloc our strings here either. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub: Use --id values for default option detectionBen Stoltz2014-01-171-7/+24
| | | | | | | | Fix Petitboot's grub.cfg parser to handle --id=label argument to menuentry, and use it (in preference to the option name) when looking for a default option. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Fixes for bison 3.xJeremy Kerr2013-12-032-7/+7
| | | | | | | | | | YYLEX_PARAM is removed in bison 3.0, so we need to pass the scanner param directly through yyparse (rather than referencing parser->scanner). Unfortunately, we don't have the lexer header available at the time we declare yyparse, so we need to pass a void * here. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Populate $prefix from config file locationJeremy Kerr2013-11-274-5/+24
| | | | | | | Rather than always using the default prefix, we should determine it from the location of the grub2 config file. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Use parser for a single parseJeremy Kerr2013-11-271-3/+3
| | | | | | | | | | Currently, we re-use a grub2 parser for different filenames, and will create one even if we find no matching files. This change only creates a parser if parser_request_file succeeds, and free() (and exits the parse) immediately after. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Fix free in load_env commandJeremy Kerr2013-11-271-3/+3
| | | | | | We only need to free the buf if parser_request_file returned success. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Fix indentation errorJeremy Kerr2013-11-271-1/+1
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Add support for -s and -f commandsJeremy Kerr2013-11-271-5/+36
| | | | | | | Implement -s and -f checks for grub, and test with the standard GRUB2 saved_default config. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* automake: Fixups for maintainer-cleanGeoff Levand2013-11-181-1/+1
| | | | Signed-off-by: Geoff Levand <geoff@infradead.org>
* lib: consolidate util macros in util/util.hJeremy Kerr2013-11-132-2/+2
| | | | | | | This change groups the offsetof, container_of and ARRAY_SIZE macros in a single header file util/util.h. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Fix potentially-uninitialised variablesJeremy Kerr2013-11-131-1/+1
| | | | | | | We've been compiling with --enable-debug; this change fixes some problems exposed by the optimiser. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Change parsers to explicitly request configuration filesNeelesh Gupta2013-11-061-6/+18
| | | | | | | | | | | | | | | | | | | Add a new function parser_request_url() to read the data from configuration files present remotely. We deprecate iterate_parser_files() and download_config() functions along with the 'filenames' and 'method' members of the 'parser' structure so that individual parsers would now require to request the configuration files data from the parser code and doesn't necessarily export the list of configuration files. Add the support to handle incoming DHCP event, done by passing all the relevant environment variables of the udhcpc to the discover code. Also, update the pxe parser code to populate the list of configuration file names as per PXELINUX convention of fallback names using mac and ip addresses of the booting machine. Signed-off-by: Neelesh Gupta <neelegup@linux.vnet.ibm.com> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Clean lexer.[ch]Jeremy Kerr2013-10-211-1/+2
| | | | | | `make distcheck` fails with a couple of failes remaining after clean. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Allow URL resourcesJeremy Kerr2013-10-142-3/+10
| | | | | | Allow URL-format specifiers for GRUB2 resources. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Fix uninitialised yylinenoJeremy Kerr2013-10-041-0/+1
| | | | | | | | | Valgrind reports an invalid usage of an uninitialised var in yyerror, causing testcase failures. Initialise lineno before we start parsing. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Implement save_env commandJeremy Kerr2013-10-042-5/+166
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Implement load_envJeremy Kerr2013-10-013-0/+116
| | | | | | | Use the new parser_request_file API to access the GRUB environment block. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: strdup strings used in the environmentJeremy Kerr2013-10-011-4/+6
| | | | | | | Use a copy of the name & value pairs that we pass to the environment, as the data loaded from load_env will be talloc_free-ed. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Add default prefixJeremy Kerr2013-10-011-1/+3
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Clean up error-handling for grub2 parser & lexerJeremy Kerr2013-09-263-16/+19
| | | | | | | Rather than printf() & exit(), use the pb logging functions and abort the parse. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Reimplement default optionsJeremy Kerr2013-09-252-2/+24
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Fix uninitialised op variableJeremy Kerr2013-09-241-0/+1
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Support var=value assignmentsJeremy Kerr2013-09-241-0/+12
| | | | | | We want to allow assignments outside of the 'set' builtin. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Add true & false builtinsJeremy Kerr2013-09-241-0/+24
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2/lexer: Require 1+ spaces for a TOKEN_DELIMJeremy Kerr2013-09-241-1/+1
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Add linux16 commandJeremy Kerr2013-09-241-0/+4
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Allow both delimiters and EOLs after a "then" reserved wordJeremy Kerr2013-09-241-2/+4
| | | | | | | | | | | Putting an if-statement on one line should be possible: if true; then echo "true"; else echo "false"; fi To do this, we'll need to allow both EOLs and TOKEN_DELIM after then and else. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Implement test builtinJeremy Kerr2013-09-241-1/+117
| | | | | | A faily simple implementation now, and could do with some testing... Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Add nops for unnecessary builtinsJeremy Kerr2013-09-241-0/+15
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Implement statement_block_executeJeremy Kerr2013-09-243-1/+12
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: unknown commands should failJeremy Kerr2013-09-241-1/+1
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Populate option idsJeremy Kerr2013-09-241-0/+3
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Allow EOF as a statement terminatorJeremy Kerr2013-09-241-1/+4
| | | | | | Files may not have a trailing newline. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
OpenPOWER on IntegriCloud