Jeremy Kerr [Mon, 4 Aug 2014 01:46:00 +0000 (09:46 +0800)]
discover/grub2: distinguish parser.h from grub2/parser.h
'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'.
Jeremy Kerr [Fri, 1 Aug 2014 03:55:45 +0000 (11:55 +0800)]
autotools: Don't link udev into everything
By default, AC_CHECK_LIB will append to $LIBS, which is used for all
link stages. Intstead, we should popuate $UDEV_LIBS, and just use that
for the single pb-discover link stage.
Jeremy Kerr [Mon, 28 Jul 2014 08:20:04 +0000 (16:20 +0800)]
autotools: Use non-recursive make
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.
Jeremy Kerr [Mon, 28 Jul 2014 04:09:14 +0000 (12:09 +0800)]
discover: Add setlocale calls in discover server
We want the discover server to respect the configured language, so we'll
need to add appropriate setlocale() calls. We use the config->lang
setting to use any previously-saved language.
Jeremy Kerr [Thu, 24 Jul 2014 07:13:24 +0000 (15:13 +0800)]
ui/ncurses: Move menu initialisation to cui code
We'll want to re-initialise the petitboot main menu (when the language
is changed), which we can't do if the items are populated entirely from
the main() function.
This change moves the menu initilisation to the cui code, we we can
re-init when necessary.
Jeremy Kerr [Tue, 24 Jun 2014 05:18:03 +0000 (13:18 +0800)]
ui/ncurses: Use a separate type for help text
Because it's initialised statically, help text won't be directly
gettext()-ed. Instead, we need to perform the gettext translation at
runtime, and pass untranslated strings into the help_screen code.
Instead of trusting callers to pass the untranslated strings though, we
encapsulate the help text data into struct help_text, so we know we have
an unstranslated string.
Jeremy Kerr [Fri, 18 Jul 2014 04:28:43 +0000 (12:28 +0800)]
ui/ncurses: allow tab/backtab to skip through a widget's fields
Since we may have a long list of devices on the configuration screen,
we'd like a way to jump between widgets. This change repeats the
PREV_FIELD/NEXT_FIELD driver request on these events.
Jeremy Kerr [Mon, 21 Jul 2014 07:51:58 +0000 (15:51 +0800)]
discover: allow separate lifetimes for network interfaces and discover devices
We want the network code's network interfaces to (potentially) persist
remove events. For example, discover devices may be removed by a user
event (this happens during a udhcpc deconfig). In this case, we want the
boot options to be removed, but the struct interface needs to stay
present.
This change adds network_(un)_register_device functions, to allow the
device handler to detach from and attach to interfaces.
Jeremy Kerr [Fri, 14 Mar 2014 02:53:04 +0000 (10:53 +0800)]
version.sh: Unify version generation
This change includes a few fixes to the version.sh script, in order to
unify the versions generated from git vs. dev- versions. We unify on a
simple YYYYMMDD format, and drop the time specifier (if you're relying
on time info, you probably have the git SHAs to lookup from instead).
We also clean up the date-generation code, by using printf's %T
formatter, on git's %ct time specification, rather than trying to
transform a %ci date.
Jeff Bailey [Fri, 14 Mar 2014 00:49:10 +0000 (08:49 +0800)]
autotools: Make petitboot autoreconfable
The standard way to regenerate the autotools bits is with 'autoreconf',
but that doesn't work with our custom bootstrap script. We only need the
bootstrap script to generate the version in configure.ac, which we can
easily do with m4_esyscmd_s instead.
This change allows autoreconfiguration with `autoreconf -f -i`.
Includes changes proposed by Yann E. Morin <yann.morin.1998@free.fr>,
and modifications from the original patch from
Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Jeff Bailey <jeffbailey@google.com> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Jeremy Kerr [Wed, 4 Jun 2014 07:45:53 +0000 (15:45 +0800)]
grub2: fix empty file handling
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.
Jeremy Kerr [Wed, 4 Jun 2014 07:22:11 +0000 (15:22 +0800)]
discover/paths: Fix wget command with https and !DEBUG
When DEBUG is undefed, we run out of wget arguments for loading https
URLs. We need an extra element in the argv array to handle all possible
arguments.
Jeremy Kerr [Thu, 22 May 2014 10:42:33 +0000 (18:42 +0800)]
discover: don't free cancelled load tasks
Currently, we have a bug when a boot task with more than one load tasks
is cancelled:
1) boot_cancel calls cleanup_cancellations, which performs a
load_url_async_cancel on all load tasks. This sets the load tasks'
states to LOAD_CANCELLED, and signals associated processes.
2) The first load task process completes, we get a load_url_process_exit
callback. This then invokes cleanup_cancellations.
3) cleanup_cancellations then (incorrectly) frees the boot task (and
hence freeing all pending load tasks) as no load tasks are in LOAD_ASYNC
state (we set them all to LOAD_CANCELLED in step 1)
4) The actual completion for the second load task attempts to reference
the now-freed task structure.
This change fixes the issue by handing the LOAD_CANCELLED state properly
- if we find a load task in this state, we consider the boot task still
pending, and delay the free until all loads are complete.
Jeff Bailey [Sun, 26 Jan 2014 00:48:24 +0000 (00:48 +0000)]
discover/yaboot: support lilo & silo for x86 and Sparc.
The yaboot.conf format is essentially the same format as silo.conf and
lilo.conf, especially if the author isn't using OF paths. This is a
cheap way of getting support for silo and lilo.
Signed-off-by: Jeff Bailey <jeffbailey@google.com> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Jeremy Kerr [Thu, 17 Apr 2014 03:40:09 +0000 (11:40 +0800)]
discover/udev: fix double free on udev_init failures
If the udev monitor or enumerate functions fail, we'll call the
udev_unref and udev_monitor_unref functions twice: once in the cleanup
path and once in the talloc destructor.
This change moves all cleanup to the talloc destructor, so we only do
the unrefs once.
Jeremy Kerr [Tue, 15 Apr 2014 03:48:00 +0000 (11:48 +0800)]
ui/ncurses: Always provide a key definition for backtab
Petitboot environments will probably want a basic terminfo defintion
(eg, vt220) rather than a full linux or xterm, but vt220 and friends
don't define a backtab key. Backtab can be useful for proper form
navigation, and without a key definition, we just get an escape, which
exits the current screen.
This change provides a static definition for KEY_BTAB, so we should
always have one available.
Jeremy Kerr [Tue, 15 Apr 2014 03:08:39 +0000 (11:08 +0800)]
ui/ncurses: Use a fixed-sized for small, known-length fields
Fields without O_STATIC can "scroll" horizontally, and we may miss a
left-hand section of text from the current display. This can mean that
the user can't leave a validated field with no indication why, if the
off-to-the-left data is not a valid entry.
This change adds a widgetset function to mark a field as fixed-size, so
we don't have this scrolling behaviour. This means that the entire field
contents will always be visible, and any validation errors can be seen.
Jeremy Kerr [Fri, 11 Apr 2014 08:11:51 +0000 (16:11 +0800)]
discover: Fix uninitialised var warnings
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.
Jeremy Kerr [Thu, 13 Mar 2014 07:18:04 +0000 (15:18 +0800)]
ui/ncurses: Ensure boot option labels are displayable as menu items
ncurses' new_item() expects the name parameter to be a "printable
string", by converting it to a wchar *, and checking that each character
is printable with iswprint(). If it fails, we won't see a boot option at
all.
This change introduces a function to convert the label into something we
know is printable, and valid UTF-8. If mbstowcs fails, we replace it
with a generic 'Invalid option' label. If we encounter a valid multibyte
string with unprintable characters, we replace those with U+fffd
REPLACEMENT CHARACTER.
Jeremy Kerr [Thu, 13 Mar 2014 02:37:20 +0000 (10:37 +0800)]
ui/ncurses: Use pmenu_item destrutor to free ncurses ITEMs
Currently, pemnu_destroy is used to free items. This means that the menu
code needs to iterate over items, and we have no way to free the ITEM *
of items that aren't in a menu.
Instead, free the ITEM in the pmenu_item destructor.
Jeremy Kerr [Wed, 12 Mar 2014 06:59:03 +0000 (14:59 +0800)]
ui/ncurses: Separate menu item creation & initialisation from insertion
Currently, the menu item creation is has two main functions:
pmenu_item_alloc and pmenu_item_setup. The latter does initialisation
(it sets item->name), and inserts the item into the menu. We have
pmenu_item_init to combine this into one, but that means we need to do
further initialisation (eg, to set on_execute) after the item has been
added to the menu.
Instead, this change use a more direct _create and _insert interface.
Create does the allocation and initialisation, while _insert does the
actual insertion.
This means new_item failures will be detected at creation time, rather
than during pmenu_insert. Also, we're now insert a completely-populated
item into the menu, rather than populating on_edit, on_execute and data
after insertion.
Because we can detect errors from creation (ie, from new_item failing),
we add handling code to cui_boot_option_add and cui_boot_editor_on_exit.
Jeremy Kerr [Wed, 12 Mar 2014 06:22:47 +0000 (14:22 +0800)]
ui/ncurses: Don't free item in pmenu_item_setup
Currently pmenu_item_setup may free its item parameter on error.
This makes it non-obvious whether the item is still allocated on exit to
the caller.
Instead, this change removes the talloc_free, and requires that the
caller do this on error. This makes the potential use-after-free in
cui_boot_editor_on_exit obvious, so we fix that too.
Jeremy Kerr [Mon, 7 Apr 2014 07:22:46 +0000 (15:22 +0800)]
lib/pb-protocol: fix deserialise of boot option priorities
Commit aa530148 introduced a priority member to struct boot_priority,
but didn't update the protocol deserialise function to properly decode
config messages. This meant we were leaving half of the struct
uninitialised, and getting invalid values in the initialised part.
This change updates the config deserialise function to do proper
handling for boot priority data.
Jeremy Kerr [Fri, 4 Apr 2014 05:05:18 +0000 (13:05 +0800)]
log: Allow runtime selection of 'debug' log level
Currently, we need to compile with -DDEBUG to implement debug-level
logging in the UIs and discover server.
Since we may not be able to easily replace a system's petitboot
binaries, this change introduces a -v|--verbose option to the discver
server and ncurses UI, which enables debug at runtime. We also move some
of the udev debug code out of an #ifdef DEBUG block.
Since petitboot is generally started on boot, we also add a little
infrastructure to pass -v to petitboot on certain system contitions:
either petitboot.debug on the kernel command line, or a petitboot,debug?
NVRAM property containing the value 'true'.
Jeremy Kerr [Thu, 3 Apr 2014 07:17:27 +0000 (15:17 +0800)]
ui/ncurses: Use tty name in default log filename
When we have multiple ncurses UIs running, we'd like to log to separate
files. Currenly, all UIs log to the same file, which makes it diffifult
to determine which UI is logging each message.
This change uses the output of ttyname() (sanitised appropriately) as a
component of the default log filename.
Jeremy Kerr [Wed, 2 Apr 2014 06:33:38 +0000 (14:33 +0800)]
discover: add reinit path
Currently, changes to settings doesn't take effect while the discover
server is running. This means we need to reboot for any changes (eg, to
network settings) to take effect.
This change introduces a reinit path. Triggered by a configuration
update, this will cause the device handler to drop all of its devices
(and boot options), and restart the discovery process from the device
sources.
Jeremy Kerr [Wed, 2 Apr 2014 06:08:26 +0000 (14:08 +0800)]
discover: move device sources to the device handler
Currently, the pb-discover main() function initialises the device
handler and the device sources.
We want to eventually be able to re-init the device sources, which will
be initiated by the handler. In this case, the handler will need
references to the sources.
This change moves the creation of the device sources to be internal to
the handler. This way, the device handler gets a reference to
everything, without having to pass pointers around in main().
We also remove the _destroy functions, as we handle everything through
talloc destructors, as all sources are parented to the handler. We also
change user_event_init and udev_init to take the handler as the first
('context') argument, to make them consistent with network_init.
Jeremy Kerr [Tue, 1 Apr 2014 08:30:27 +0000 (16:30 +0800)]
discover/udev: don't propagate non-fatal errors from udev_process
Currently, we have a bug where non-zero return codes from
udev_handle_dev_* cause the udev worker from deregistering from the
waiter poll loop. This is becasue udev_process is propagating these
errors, causing the deregistration.
This change stops propagation of non-fatal errors, so we don't
deregister.
Jeremy Kerr [Thu, 13 Mar 2014 02:07:12 +0000 (10:07 +0800)]
discover: Use ID_FS_TYPE property for filesystem type detection
Currently, we don't hand any -t option to mount, as we expect the mount
binary to do autodetection of the filesystem type for us.
Turns out this isn't great with busybox mount, (which we're likely to be
using in petitboot builds), which implements "autodetection" by trying
the mount() syscall with every fs type in /proc/filesystems, until one
succeeds.
We expect a lot of the mount calls to fail, as we currently try to mount
everything (and abort discovery on devices that don't mount), including
non-filesystem partitions. On a test machine with 560 block devices, and
37 entries in /proc/partitions, this results in around 20,000 calls to
mount().
A better way would be to pass a -t option to mount. It turns out that
udev uses libblkid to probe the filesystem type, which is available in
the ID_FS_TYPE property. This change only attempts to mount filesystems
with this property, and passes an explicit fstype to the mount binary.
Jeremy Kerr [Fri, 7 Mar 2014 05:46:49 +0000 (13:46 +0800)]
discover/udev: Register udev monitor before enumerating devices
Currently, we enumerate udev devices before setting up our monitor. This
means that we may lose devices that udev discovers after we start the
enumeration, but before the monitor is registered.
This change enables the monitor before enumeration, so we don't lose
devices. We add a filter to the enumeration code to only parse
completely initialised devices.
This means we may need to handle change events as the main source of
device notifications. We keep the existing CDROM event handler, but
check for new devices and handle those as an add.
Jeremy Kerr [Fri, 7 Mar 2014 01:05:00 +0000 (09:05 +0800)]
discover: don't retry mount without ro option
Currently, if the read-only mount fails during device discovery, we
retry without the '-o ro' option. This was originally due to the
read-only mount failing when a device was already mounted elsewhere.
Since we check for exsiting mounts now, we can drop this retry.