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.
Jeremy Kerr [Fri, 24 Jan 2014 06:39:37 +0000 (14:39 +0800)]
discover: Add support for checking directories in parser API
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.
Jeremy Kerr [Tue, 21 Jan 2014 00:27:48 +0000 (08:27 +0800)]
discover/paths: Check process exit status when loading URLs
Currently, we may report incorrect success when loading a URL, as we
only check the return value of process_run_sync() (and not the process
exit status itself) in load_process_to_local_file.
Jeremy Kerr [Mon, 20 Jan 2014 00:58:49 +0000 (08:58 +0800)]
utils/pb-udhcpc: Unify references to DHCP bootfile parameter
udhcpc may pass the bootfile parameter as either $bootfile or
$boot_file, depending on whether the option is present in the BOOTP
header, or as a DHCP vendor option. We have code in pb-udhcpc to unify
this to $bootfile, but we only use the unified value in one of the user
events.
This change uses the correct value of bootfile, and fixes the check to
conditionally generate the explicit add event. We also need to update
the user-event code to use the right event parameter name.
Jeremy Kerr [Mon, 20 Jan 2014 00:51:11 +0000 (08:51 +0800)]
utils/pb-udhcpc: Fix incorrect reference to $interface
We have a typo in the udhcpc hook, where we're not referncing the
interface variable correctly. This means we'll get the same device
identifier for all netboot options.
Jeremy Kerr [Fri, 17 Jan 2014 07:51:54 +0000 (15:51 +0800)]
discover: Support DHCP "pathprefix" configuration option
This change implements support for the DHCP "pathprefix" option. We use
the following logic:
- If pathprefix is present and a full URL, we base the config file
location on pathprefix + conffile
- If pathprefix is present but not a full URL, we use it as the path
component of the URL, and pick up the host from other parameters in
the DHCP response
- If no pathprefix is present, we determine the configuration prefix
from the DHCP bootfile parameter.
Jeremy Kerr [Fri, 17 Jan 2014 08:36:41 +0000 (16:36 +0800)]
test/parser: Check for full URLs in parser tests
At present, we only match the 'file' portion of a URL in the parser
tests, so we "serve" a file if just the filename (but not the scheme,
hostname or path) matches the file we set with test_read_conf_embedded.
This change introduces test_read_conf_embedded_url, which we can use to
specify a full URL. In this case, the fake parser_request_file matches
the entire URL before returning the file data.
Jeremy Kerr [Fri, 17 Jan 2014 06:50:54 +0000 (14:50 +0800)]
discover: Don't rely on ctx->conf_url side-effect in user_event_parse_conf_url
Currently, user_event_parse_conf_url sets dc->conf_url if it detects we
have a full URL (rather than a base URL). This is a little too subtle,
so replace it with an explicit output parameter.
Ben Stoltz [Wed, 15 Jan 2014 23:10:25 +0000 (15:10 -0800)]
discover/grub: Use --id values for default option detection
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.
Jeremy Kerr [Thu, 16 Jan 2014 01:13:20 +0000 (09:13 +0800)]
discover: Bring down configured interfaces on discover server exit.
We want to down the interfaces that we brought up, so hook up the
network_shutdown function to the discover exit path. Also, we only want
to down interfaces that we've configured, and exclude lo.
Jeremy Kerr [Tue, 14 Jan 2014 07:44:10 +0000 (15:44 +0800)]
lib/process: Add add_stderr flag to process module
For some process execution functions, we'd like to capture stderr as
well as stdout. Currently, we unconditionally redirect subprocess stderr
to the petitboot log file.
This change adds an add_stderr flag to struct process, which indicates
to the process library that we want stderr as well as stdout. If this is
specified, the subprocess' stderr is captured to stdout_buf.
Jeremy Kerr [Tue, 14 Jan 2014 02:56:41 +0000 (10:56 +0800)]
discover/yaboot: Clear globals_done when we see an image definition
Currently, we have a bug where a 'known_name' that appears before an
image section will cause globals_done to be set, and we don't see any
further global variables.
This change sets globals_done only once we see an image section.
Jeremy Kerr [Mon, 23 Dec 2013 08:42:21 +0000 (16:42 +0800)]
config/powerpc: Always call update_network_config
Currently, we have a bug when setting the default network configuration
(ie, no devices have any specific config), as we won't call
update_network_config to clear out the value of the petitboot,network
parameter.
This change always invokes update_network_config, regardless of the
number of interfaces configured. This ensures we clear out the
petitboot,network param, which is then synced to nvram if the param has
changed.
We'd like to do some validation of the system configuration parameters,
so add a few validation types to the widget code. We currently need
integer, ipv4 address and multiple ipv4 address types. These are
implemented as small wrappers around the ncurses form validator code.
Jeremy Kerr [Mon, 16 Dec 2013 02:49:29 +0000 (10:49 +0800)]
sysinfo: Add interface link status to sysinfo data
This changes adds a 'link' parameter to the interface information sent
in sysinfo messages. The discover network code populates this from the
incoming netlink messages.
Jeremy Kerr [Thu, 5 Dec 2013 06:32:28 +0000 (14:32 +0800)]
discover/boot: Fix condition for updating boot params
In commit 823958fb, we change to use struct process, but left in the
check for rc == BOOT_HOOK_EXIT_UPDATE. We actually want to check
process->exit_status here, not rc.
Jeremy Kerr [Tue, 3 Dec 2013 07:14:53 +0000 (15:14 +0800)]
discover/grub2: Fixes for bison 3.x
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.
Jeremy Kerr [Fri, 29 Nov 2013 02:47:10 +0000 (10:47 +0800)]
discover: Fix CDROM handling
Currently, we don't handle CDROM devices well; we'll try to mount on
boot, and not detect any media changes. Also, the default rules shipping
with udev will put the CDROM tray into a locked state, blocking eject
from working.
This change adds a set of cdrom utility functions, which the udev code
can use to properly initialise cdrom devices and handle eject and media
change requests.
In an upcoming change, we'll populate $prefix (which is used to locate
the environment file) based on the location of the config file, so these
paths will need to be consistent.
Jeremy Kerr [Fri, 22 Nov 2013 06:12:59 +0000 (14:12 +0800)]
ui/ncurses/nc-widgets: Unify select key
We have a few instances where we check for a 'select' action (enter or
space key event), and some are inconsistent. Unify these with a
key_is_select() function.
Jeremy Kerr [Tue, 19 Nov 2013 06:39:41 +0000 (17:39 +1100)]
ui/ncurses: Fix use-after-free when exiting boot option editor
After we've called on_exit, we can no longer use the boot editor. This
change moves individual button callbacks into process_key, which returns
to the main loop.
Jeremy Kerr [Tue, 19 Nov 2013 00:52:49 +0000 (11:52 +1100)]
ui/ncurses: Draw boot editor into a scrollable pad
Like the config editor, draw the boot editor into a pad instead of
directly into the sub window. This means that long device lists will be
handled correctly.
Jeremy Kerr [Sun, 17 Nov 2013 08:36:55 +0000 (19:36 +1100)]
ui/ncurses: Add device selector to boot editor
Rather than expecting users to enter full (prefixed) mount paths, add a
select widget to pick a device, and we automatically add the prefix when
the form is submitted.
Jeremy Kerr [Sun, 17 Nov 2013 03:04:08 +0000 (14:04 +1100)]
ui/ncurses: Make boot editor API consistent with config & sysinfo screens
The boot-editor API is a little more exposed than it needs to be: the
boot_editor struct does not need to be available to other files, and the
init function and on_exit functions differ from those provided for the
config and sysinfo screens.
This change unifies the boot_editor API with those for the other
screens.
Jeremy Kerr [Tue, 19 Nov 2013 04:25:43 +0000 (15:25 +1100)]
discover: Use pxeconffile for udhcpc option name
The patch that went upstream for udhcpc's option 209 handling uses the
option name 'pxeconffile' rather than 'conffile', and it was added as a
non-default option:
Jeremy Kerr [Fri, 25 Oct 2013 01:19:35 +0000 (09:19 +0800)]
nui/ncurses: Allow config screen updates
We may receive configuration (or sysinfo) data after the configuration
screen has been displayed. Implement config_screen_update and redraw the
widgetset when new config data arrives.
Jeremy Kerr [Thu, 17 Oct 2013 05:52:42 +0000 (13:52 +0800)]
ui/ncurses: Add sysinfo screen
Add a simple screen for displaying the struct system_info. We add this
to the main menu as a selectable option, and separate it from the boot
option list with an unselectable blank entry.
Jeremy Kerr [Thu, 17 Oct 2013 04:03:51 +0000 (12:03 +0800)]
ui/common: Don't talloc_free sysinfo and status explicitly
Currently, we talloc_free() the sysinfo and status messages in the
discover client, right after performing the ui's callback.
However, the client may wish to keep a reference to this information
beyond the callback invocation. This change introduces a per-message
talloc context, which these structures are allocated under. This allows
the callbacks to talloc_steal() anything they wish to keep a reference
to.