-
Notifications
You must be signed in to change notification settings - Fork 26
/
oops_parser.h
76 lines (64 loc) · 2.18 KB
/
oops_parser.h
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* This program is part of the Clear Linux Project
*
* Copyright 2015 Intel Corporation
*
* This program is free software; you can redistribute it and/or modify it under
* the terms and conditions of the GNU Lesser General Public License, as
* published by the Free Software Foundation; either version 2.1 of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
#pragma once
#define MAX_LINES 100
#include "nica/nc-string.h"
#include <stdbool.h>
#include <regex.h>
/*
* Contains all possible patterns that start a kernel oops msg.
* Also Defines the severity and classification associated with each oops.
*/
struct oops_pattern {
const char *begin_line;
const char *classification;
int severity;
bool is_regex;
regex_t regex;
};
/*
* This struct holds the lines of an oops messsage once the start has been
* detected.
*/
struct oops_log_msg {
char *lines[MAX_LINES];
int length;
struct oops_pattern *pattern;
};
/* Callback function to be passed when the oops parser is invoked async */
typedef void (*oops_handler_t)(struct oops_log_msg *msg);
/* Cleanup the parser when called async */
void oops_parser_cleanup(void);
/*
* Initialise the parser for async handling.
* Sets up the handler to be invoked when a complete oops has been detected and
* handled.
*/
void oops_parser_init(oops_handler_t handler);
/*
* Handle a single line of the oops msg.
* Call this repeatedly for a oops log line.
*/
void parse_single_line(char *line, size_t size);
/* Parses a payload from an oops msg*/
nc_string *parse_payload(struct oops_log_msg *msg);
/* Given an entire oops log, verifies that the log is an oops log and
* extracts the lines into an oops struct.
*/
bool handle_entire_oops(char *buf, long size, struct oops_log_msg *msg);
/* Frees up the oops log lines from the oops struct */
void oops_msg_cleanup(struct oops_log_msg *msg);
/* vi: set ts=8 sw=8 sts=4 et tw=80 cino=(0: */