summaryrefslogtreecommitdiffstats
path: root/discover/native/native.c
diff options
context:
space:
mode:
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>2018-10-30 15:26:04 +1100
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>2018-11-16 13:55:13 +1100
commit646d77d8156ad72da1c24f734a029a525ba4bed9 (patch)
tree8eaa5db080f5c2b733b506fd82eec773ac2afdb3 /discover/native/native.c
parent638f16c7683db165154bbe53772c4b864f9dc90d (diff)
downloadtalos-petitboot-646d77d8156ad72da1c24f734a029a525ba4bed9.tar.gz
talos-petitboot-646d77d8156ad72da1c24f734a029a525ba4bed9.zip
discover: Reimplement native-parser as a Bison parser
Occasionally you look at some code and realise that a) this never gets built, and b) even if it did it would never compile. Today's example is native-parser.c which we must have just assumed worked for quite a while. The native parser has bitrotted entirely and needs to be brought up to date. While we're here, lets take the chance to implement a proper grammar for it. This helps us reason more effectively about the parser, lets us extend it easily in the future, and.. I wanted to write a Bison parser too. This implements most of the old functionality, but drops off some smaller details like settings icons which needs some separate attention to bring up to date. Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Diffstat (limited to 'discover/native/native.c')
-rw-r--r--discover/native/native.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/discover/native/native.c b/discover/native/native.c
new file mode 100644
index 0000000..964ad1d
--- /dev/null
+++ b/discover/native/native.c
@@ -0,0 +1,55 @@
+#include <assert.h>
+#include <string.h>
+#include <i18n/i18n.h>
+
+#include <talloc/talloc.h>
+#include <url/url.h>
+
+#include <discover/resource.h>
+#include <discover/parser.h>
+#include <discover/parser-utils.h>
+
+#include "native.h"
+
+static const char *const native_conf_files[] = {
+ "/boot/petitboot.conf",
+ "/petitboot.conf",
+ NULL
+};
+
+static int native_parse(struct discover_context *dc)
+{
+ const char * const *filename;
+ struct native_parser *parser;
+ int len, rc;
+ char *buf;
+
+ /* Support block device boot only at present */
+ if (dc->event)
+ return -1;
+
+ for (filename = native_conf_files; *filename; filename++) {
+ rc = parser_request_file(dc, dc->device, *filename, &buf, &len);
+ if (rc)
+ continue;
+
+ parser = native_parser_create(dc);
+ native_parser_parse(parser, *filename, buf, len);
+ device_handler_status_dev_info(dc->handler, dc->device,
+ _("Parsed native configuration from %s"),
+ *filename);
+ talloc_free(buf);
+ talloc_free(parser);
+ break;
+ }
+
+ return 0;
+}
+
+static struct parser native_parser = {
+ .name = "native",
+ .parse = native_parse,
+ .resolve_resource = resolve_devpath_resource,
+};
+
+register_parser(native_parser);
OpenPOWER on IntegriCloud