]> git.ozlabs.org Git - petitboot/blob - discover/event-parser.c
discover: Separate temporary and permanent device data
[petitboot] / discover / event-parser.c
1 #define _GNU_SOURCE
2
3 #include <assert.h>
4
5 #include "log/log.h"
6 #include "talloc/talloc.h"
7 #include "event.h"
8 #include "parser-utils.h"
9 #include "device-handler.h"
10
11 /**
12  * parse_user_event - Parse a user event.
13  *
14  * Understands params: name, image, args.
15  */
16
17 int parse_user_event(struct discover_context *ctx, struct event *event)
18 {
19         struct boot_option *opt;
20         struct device *dev;
21         const char *p;
22
23         dev = ctx->device->device;
24
25         opt = talloc_zero(dev, struct boot_option);
26
27         if (!opt)
28                 goto fail;
29
30         p = event_get_param(event, "name");
31
32         if (!p) {
33                 pb_log("%s: no name found\n", __func__);
34                 goto fail;
35         }
36
37         opt->id = talloc_asprintf(opt, "%s#%s", dev->id, p);
38         opt->device_id = talloc_strdup(opt, dev->id);
39         opt->name = talloc_strdup(opt, p);
40
41         p = event_get_param(event, "image");
42         assert(p);
43
44         if (!p) {
45                 pb_log("%s: no image found\n", __func__);
46                 goto fail;
47         }
48
49         opt->boot_image_file = talloc_strdup(opt, p);
50
51         p = event_get_param(event, "args");
52         assert(p);
53
54         opt->boot_args = talloc_strdup(opt, p);
55
56         opt->description = talloc_asprintf(opt, "%s %s", opt->boot_image_file,
57                 opt->boot_args);
58
59         discover_context_add_boot_option(ctx, opt);
60
61         return 0;
62
63 fail:
64         talloc_free(opt);
65         return -1;
66 }