-
Notifications
You must be signed in to change notification settings - Fork 81
/
rasdaemon.c
215 lines (185 loc) · 4.32 KB
/
rasdaemon.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2013 Mauro Carvalho Chehab <[email protected]>
*/
#include <argp.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "ras-events.h"
#include "ras-logger.h"
#include "ras-record.h"
#include "types.h"
/*
* Arguments(argp) handling logic and main
*/
#define TOOL_NAME "rasdaemon"
#define TOOL_DESCRIPTION "RAS daemon to log the RAS events."
#define ARGS_DOC "<options>"
#define DISABLE "DISABLE"
const char *argp_program_version = TOOL_NAME " " VERSION;
const char *argp_program_bug_address = "Mauro Carvalho Chehab <[email protected]>";
struct arguments {
int record_events;
int enable_ras;
int enable_ipmitool;
int foreground;
int offline;
};
enum OFFLINE_ARG_KEYS {
SMCA = 0x100,
MODEL,
FAMILY,
BANK_NUM,
IPID_REG,
STATUS_REG,
SYNDROME_REG
};
struct ras_mc_offline_event event;
static error_t parse_opt(int k, char *arg, struct argp_state *state)
{
struct arguments *args = state->input;
switch (k) {
case 'e':
args->enable_ras++;
break;
case 'd':
args->enable_ras--;
break;
#ifdef HAVE_SQLITE3
case 'r':
args->record_events++;
break;
#endif
#ifdef HAVE_OPENBMC_UNIFIED_SEL
case 'i':
args->enable_ipmitool++;
break;
#endif
case 'f':
args->foreground++;
break;
#ifdef HAVE_MCE
case 'p':
if (state->argc < 4)
argp_state_help(state, stdout, ARGP_HELP_LONG | ARGP_HELP_EXIT_ERR);
args->offline++;
break;
#endif
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
#ifdef HAVE_MCE
static error_t parse_opt_offline(int key, char *arg,
struct argp_state *state)
{
switch (key) {
case SMCA:
event.smca = true;
break;
case MODEL:
event.model = strtoul(state->argv[state->next], NULL, 0);
break;
case FAMILY:
event.family = strtoul(state->argv[state->next], NULL, 0);
break;
case BANK_NUM:
event.bank = atoi(state->argv[state->next]);
break;
case IPID_REG:
event.ipid = strtoull(state->argv[state->next], NULL, 0);
break;
case STATUS_REG:
event.status = strtoull(state->argv[state->next], NULL, 0);
break;
case SYNDROME_REG:
event.synd = strtoull(state->argv[state->next], NULL, 0);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
#endif
long user_hz;
int main(int argc, char *argv[])
{
struct arguments args;
int idx = -1;
choices_disable = getenv(DISABLE);
#ifdef HAVE_MCE
const struct argp_option offline_options[] = {
{"smca", SMCA, 0, 0, "AMD SMCA Error Decoding"},
{"model", MODEL, 0, 0, "CPU Model"},
{"family", FAMILY, 0, 0, "CPU Family"},
{"bank", BANK_NUM, 0, 0, "Bank Number"},
{"ipid", IPID_REG, 0, 0, "IPID Register (for SMCA systems only)"},
{"status", STATUS_REG, 0, 0, "Status Register"},
{"synd", SYNDROME_REG, 0, 0, "Syndrome Register"},
{0, 0, 0, 0, 0, 0},
};
struct argp offline_argp = {
.options = offline_options,
.parser = parse_opt_offline,
.doc = TOOL_DESCRIPTION,
.args_doc = ARGS_DOC,
};
struct argp_child offline_parser[] = {
{&offline_argp, 0, "Post-Processing Options:", 0},
{0, 0, 0, 0},
};
#endif
const struct argp_option options[] = {
{"enable", 'e', 0, 0, "enable RAS events and exit", 0},
{"disable", 'd', 0, 0, "disable RAS events and exit", 0},
#ifdef HAVE_SQLITE3
{"record", 'r', 0, 0, "record events via sqlite3", 0},
#endif
{"foreground", 'f', 0, 0, "run foreground, not daemonize"},
#ifdef HAVE_OPENBMC_UNIFIED_SEL
{"ipmitool", 'i', 0, 0, "enable ipmitool logging", 0},
#endif
#ifdef HAVE_MCE
{"post-processing", 'p', 0, 0,
"Post-processing MCE's with raw register values"},
#endif
{ 0, 0, 0, 0, 0, 0 }
};
const struct argp argp = {
.options = options,
.parser = parse_opt,
.doc = TOOL_DESCRIPTION,
.args_doc = ARGS_DOC,
#ifdef HAVE_MCE
.children = offline_parser,
#endif
};
memset(&args, 0, sizeof(args));
user_hz = sysconf(_SC_CLK_TCK);
argp_parse(&argp, argc, argv, 0, &idx, &args);
if (idx < 0) {
argp_help(&argp, stderr, ARGP_HELP_STD_HELP, TOOL_NAME);
return -1;
}
if (args.enable_ras) {
int enable;
enable = (args.enable_ras > 0) ? 1 : 0;
toggle_ras_mc_event(enable);
return 0;
}
#ifdef HAVE_MCE
if (args.offline) {
ras_offline_mce_event(&event);
return 0;
}
#endif
openlog(TOOL_NAME, 0, LOG_DAEMON);
if (!args.foreground)
if (daemon(0, 0))
exit(EXIT_FAILURE);
handle_ras_events(args.record_events, args.enable_ipmitool);
return 0;
}