]> git.ozlabs.org Git - petitboot/blob - discover/event-parser.c
discover: Remove empty routine udev_trigger
[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 discover_boot_option *d_opt;
20         struct boot_option *opt;
21         struct device *dev;
22         const char *p;
23
24         dev = ctx->device->device;
25
26         d_opt = discover_boot_option_create(ctx, ctx->device);
27         opt = d_opt->option;
28
29         if (!d_opt)
30                 goto fail;
31
32         p = event_get_param(event, "name");
33
34         if (!p) {
35                 pb_log("%s: no name found\n", __func__);
36                 goto fail;
37         }
38
39         opt->id = talloc_asprintf(opt, "%s#%s", dev->id, p);
40         opt->device_id = talloc_strdup(opt, dev->id);
41         opt->name = talloc_strdup(opt, p);
42
43         p = event_get_param(event, "image");
44         assert(p);
45
46         if (!p) {
47                 pb_log("%s: no image found\n", __func__);
48                 goto fail;
49         }
50
51         opt->boot_image_file = talloc_strdup(opt, p);
52
53         p = event_get_param(event, "args");
54         assert(p);
55
56         opt->boot_args = talloc_strdup(opt, p);
57
58         opt->description = talloc_asprintf(opt, "%s %s", opt->boot_image_file,
59                 opt->boot_args);
60
61         discover_context_add_boot_option(ctx, d_opt);
62
63         return 0;
64
65 fail:
66         talloc_free(d_opt);
67         return -1;
68 }