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