]> git.ozlabs.org Git - petitboot/blob - discover/event-parser.c
Add discover user event
[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
10 int parse_user_event(struct device *device, struct event *event)
11 {
12         struct boot_option *opt;
13         const char *p;
14
15         opt = talloc_zero(device, struct boot_option);
16
17         if (!opt)
18                 goto fail;
19
20         p = event_get_param(event, "name");
21
22         if (!p) {
23                 pb_log("%s: no name found\n", __func__);
24                 goto fail;
25         }
26
27         opt->id = talloc_asprintf(opt, "%s#%s", device->id, p);
28         opt->name = talloc_strdup(opt, p);
29
30         p = event_get_param(event, "image");
31         assert(p);
32
33         if (!p) {
34                 pb_log("%s: no image found\n", __func__);
35                 goto fail;
36         }
37
38         opt->boot_image_file = talloc_strdup(opt, p);
39
40         p = event_get_param(event, "args");
41         assert(p);
42
43         opt->boot_args = talloc_strdup(opt, p);
44
45         opt->description = talloc_asprintf(opt, "%s %s", opt->boot_image_file,
46                 opt->boot_args);
47
48         device_add_boot_option(device, opt);
49
50         return 0;
51
52 fail:
53         talloc_free(opt);
54         return -1;
55 }