-
Notifications
You must be signed in to change notification settings - Fork 3
/
rebootlog.c
55 lines (44 loc) · 1.26 KB
/
rebootlog.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* SPDX-License-Identifier: BSD-3-Clause */
#include "ucentral.h"
#define CRASHLOG "/tmp/crashlog"
#define CONSOLELOG "/tmp/consolelog"
static struct blob_buf rebootlog;
enum {
REBOOT_LOG,
__REBOOT_MAX,
};
static const struct blobmsg_policy crash_policy[__REBOOT_MAX] = {
[REBOOT_LOG] = { .name = "crashlog", .type = BLOBMSG_TYPE_ARRAY },
};
static const struct blobmsg_policy console_policy[__REBOOT_MAX] = {
[REBOOT_LOG] = { .name = "consolelog", .type = BLOBMSG_TYPE_ARRAY },
};
static void
rebootlog_init(const struct blobmsg_policy *policy, char *type, char *file)
{
struct blob_attr *tb[__REBOOT_MAX] = {};
struct stat s = {};
if (stat(file, &s))
return;
blob_buf_init(&rebootlog, 0);
if (blobmsg_add_json_from_file(&rebootlog, file)) {
blobmsg_parse(policy, __REBOOT_MAX, tb, blob_data(rebootlog.head),
blob_len(rebootlog.head));
if (tb[REBOOT_LOG])
rebootlog_send(type, tb[REBOOT_LOG]);
else
log_send("failed to parse the rebootlog", LOG_ERR);
} else {
log_send("found a rebootlog that is not valid json", LOG_ERR);
}
blob_buf_free(&rebootlog);
unlink(file);
}
void
crashlog_init(void) {
rebootlog_init(crash_policy, "crashlog", CRASHLOG);
}
void
consolelog_init(void) {
rebootlog_init(console_policy, "console", CONSOLELOG);
}