[RFC PATCH 0/8] Introduce pb-plugin 'commands' & Rust PoC

Samuel Mendoza-Jonas sam at mendozajonas.com
Tue Dec 18 15:19:45 AEDT 2018


This series extends the pb-plugin API with support for defining specific
command & argument combinations to present to the user to run. These can
either be executables contained in the plugin or commands already
present in the Petitboot environment. Arguments can be of several types,
the values of which are substituted into an argument format string
appended to the command.

While making the pb-plugin interface more user-friendly, the original
idea behind this approach is to provide a way to include extra "platform
options" in the Petitboot UI without having to add in dedicated
configuration options or additional screens per-platform (or per
sub-platform as in some cases). Instead this dynamically displays
options in nc-plugin as read from a plugin 'command' file. These could
range from including a platform-specific utility to configure a certain
feature, to something as simple as setting some specific NVRAM
parameters from the UI with a description of the parameter to aid the
user.

The current changes still depend on pb-discover finding a plugin; most
likely I'll introduce an option to find 'baked in' plugins at that can
be included at build time in a directory like /etc/petitboot. Comments
on areas such as the command format (see patch 3) are very welcome.

Patch 1 of the series also acts a proof-of-concept of including a more
modern language (in this case, Rust) in Petitboot features. The new
directory lib/rust includes a small amount of Rust to parse the
plugin command JSON file and some helper functions to handle the
interaction between C and Rust.
Aside from being a bit of fun to experiment with this avoids introducing
ever more string parsing in C and opens an avenue to using safer
languages where appropriate. Built statically so the runtime isn't
required and stripping at compile time the resulting size is manageable
and it fits well enough into the existing Autoconf. Comments,
suggestions, and intense bikeshedding welcome, but if this shakes out
well enough it could be an interesting addition to Petitboot.

Samuel Mendoza-Jonas (8):
  rust: Add rust interface for parsing JSON
  lib/pb-protocol: Reflect additions to plugin_option
  utils: Add plugin_commands parameter
  utils/pb-exec: Prepend sudo if normal user
  discover/device-handler: Read command files if present
  ui/ncurses: Don't post screen after command
  ui/ncurses: Add current_field accessor
  ui/ncurses: Present plugin commands in nc-plugin

 Makefile.am                   |   1 -
 configure.ac                  |   9 ++
 discover/device-handler.c     |   8 ++
 discover/user-event.c         |   2 +
 lib/Makefile.am               |   9 +-
 lib/pb-protocol/pb-protocol.c | 168 ++++++++++++++++++++++
 lib/pb-protocol/pb-protocol.h |   6 +
 lib/rust/Cargo.lock           | 117 ++++++++++++++++
 lib/rust/Cargo.toml           |  20 +++
 lib/rust/Makefile.am          |  30 ++++
 lib/rust/build.rs             |  70 ++++++++++
 lib/rust/rustlibs.c           | 109 +++++++++++++++
 lib/rust/rustlibs.h           |  11 ++
 lib/rust/src/lib.rs           | 230 ++++++++++++++++++++++++++++++
 lib/types/types.h             |  30 ++++
 test/lib/Makefile.am          |   3 +-
 test/lib/test-protocol.c      | 158 +++++++++++++++++++++
 ui/ncurses/nc-cui.c           |   1 -
 ui/ncurses/nc-plugin.c        | 256 +++++++++++++++++++++++++++++++---
 ui/ncurses/nc-widgets.c       |  13 ++
 ui/ncurses/nc-widgets.h       |   1 +
 utils/pb-exec                 |   8 +-
 utils/pb-plugin               |   8 +-
 23 files changed, 1243 insertions(+), 25 deletions(-)
 create mode 100644 lib/rust/Cargo.lock
 create mode 100644 lib/rust/Cargo.toml
 create mode 100644 lib/rust/Makefile.am
 create mode 100644 lib/rust/build.rs
 create mode 100644 lib/rust/rustlibs.c
 create mode 100644 lib/rust/rustlibs.h
 create mode 100644 lib/rust/src/lib.rs
 create mode 100644 test/lib/test-protocol.c

-- 
2.20.0



More information about the Petitboot mailing list