Lines 1-5
Link Here
|
1 |
--- mcelog.c.orig 2010-01-20 18:36:52.000000000 -0800 |
1 |
--- mcelog.c.orig 2016-02-10 18:38:43 UTC |
2 |
+++ mcelog.c 2012-09-22 02:34:19.182116917 -0700 |
2 |
+++ mcelog.c |
3 |
@@ -20,9 +20,22 @@ |
3 |
@@ -20,9 +20,22 @@ |
4 |
#define _GNU_SOURCE 1 |
4 |
#define _GNU_SOURCE 1 |
5 |
#include <sys/fcntl.h> |
5 |
#include <sys/fcntl.h> |
Lines 23-31
Link Here
|
23 |
#include <stdlib.h> |
23 |
#include <stdlib.h> |
24 |
#include <stdio.h> |
24 |
#include <stdio.h> |
25 |
#include <string.h> |
25 |
#include <string.h> |
26 |
@@ -58,9 +71,25 @@ |
26 |
@@ -61,9 +74,25 @@ |
27 |
#include "yellow.h" |
27 |
#include "bus.h" |
28 |
#include "page.h" |
28 |
#include "unknown.h" |
29 |
|
29 |
|
30 |
+struct mca_record { |
30 |
+struct mca_record { |
31 |
+ uint64_t mr_status; |
31 |
+ uint64_t mr_status; |
Lines 49-55
Link Here
|
49 |
|
49 |
|
50 |
int ignore_nodev; |
50 |
int ignore_nodev; |
51 |
int filter_bogus = 1; |
51 |
int filter_bogus = 1; |
52 |
@@ -71,12 +100,18 @@ |
52 |
@@ -74,7 +103,9 @@ int ascii_mode; |
53 |
int dump_raw_ascii; |
53 |
int dump_raw_ascii; |
54 |
int daemon_mode; |
54 |
int daemon_mode; |
55 |
static char *inputfile; |
55 |
static char *inputfile; |
Lines 59-89
Link Here
|
59 |
static int foreground; |
59 |
static int foreground; |
60 |
int filter_memory_errors; |
60 |
int filter_memory_errors; |
61 |
static struct config_cred runcred = { .uid = -1U, .gid = -1U }; |
61 |
static struct config_cred runcred = { .uid = -1U, .gid = -1U }; |
62 |
static int numerrors; |
62 |
@@ -83,6 +114,10 @@ static char pidfile_default[] = PID_FILE |
63 |
static char *pidfile; |
63 |
static char logfile_default[] = LOG_FILE; |
|
|
64 |
static char *pidfile = pidfile_default; |
65 |
static char *logfile; |
64 |
+#ifdef __FreeBSD__ |
66 |
+#ifdef __FreeBSD__ |
65 |
+static char *execfile; |
67 |
+static char *execfile; |
66 |
+static char *corefile; |
68 |
+static char *corefile; |
67 |
+#endif |
69 |
+#endif |
68 |
|
70 |
static int debug_numerrors; |
69 |
static void check_cpu(void); |
71 |
int imc_log = -1; |
70 |
|
72 |
static int check_only = 0; |
71 |
@@ -393,6 +428,7 @@ |
73 |
@@ -482,6 +517,7 @@ static void dump_mce_raw_ascii(struct mc |
72 |
Wprintf("\n"); |
74 |
Wprintf("\n"); |
73 |
} |
75 |
} |
74 |
|
76 |
|
75 |
+#ifdef __Linux__ |
77 |
+#ifdef __Linux__ |
76 |
void check_cpu(void) |
78 |
int is_cpu_supported(void) |
77 |
{ |
79 |
{ |
78 |
enum { |
80 |
enum { |
79 |
@@ -460,7 +496,45 @@ |
81 |
@@ -552,13 +588,58 @@ int is_cpu_supported(void) |
80 |
} else |
82 |
|
81 |
Eprintf("warning: Cannot open /proc/cpuinfo\n"); |
83 |
return 1; |
82 |
} |
84 |
} |
83 |
+#endif |
85 |
+#endif |
84 |
+ |
86 |
|
85 |
+#ifdef __FreeBSD__ |
87 |
+#ifdef __FreeBSD__ |
86 |
+void check_cpu(void) |
88 |
+int is_cpu_supported(void) |
87 |
+{ |
89 |
+{ |
88 |
+ char vendor[20]; |
90 |
+ char vendor[20]; |
89 |
+ u_int regs[4]; |
91 |
+ u_int regs[4]; |
Lines 92-98
Link Here
|
92 |
+ static int checked; |
94 |
+ static int checked; |
93 |
+ |
95 |
+ |
94 |
+ if (checked) |
96 |
+ if (checked) |
95 |
+ return; |
97 |
+ return 1; |
96 |
+ |
98 |
+ |
97 |
+ checked = 1; |
99 |
+ checked = 1; |
98 |
+ |
100 |
+ |
Lines 109-136
Link Here
|
109 |
+ |
111 |
+ |
110 |
+ if (cpu_forced) |
112 |
+ if (cpu_forced) |
111 |
+ ; |
113 |
+ ; |
112 |
+ else if (!strcmp(vendor,"AuthenticAMD") && |
114 |
+ else if (!strcmp(vendor,"AuthenticAMD")) { |
113 |
+ (family == 15 || family == 16 || family == 17)) |
115 |
+ if (family == 15) { |
114 |
+ cputype = CPU_K8; |
116 |
+ cputype = CPU_K8; |
115 |
+ else if (!strcmp(vendor,"GenuineIntel")) |
117 |
+ } else if (family >= 16) { |
116 |
+ cputype = select_intel_cputype(family, model); |
118 |
+ SYSERRprintf("ERROR: AMD Processor family %d: mcelog does not support this processor. Please use the edac_mce_amd module instead.\n", family); |
|
|
119 |
+ return 0; |
120 |
+ } |
121 |
+ } else if (!strcmp(vendor,"GenuineIntel")) |
122 |
+ cputype = select_intel_cputype(family, model); |
117 |
+ /* Add checks for other CPUs here */ |
123 |
+ /* Add checks for other CPUs here */ |
|
|
124 |
+ else |
125 |
+ return 1; |
118 |
+} |
126 |
+} |
119 |
+#endif |
127 |
+#endif |
120 |
|
128 |
+ |
121 |
+#ifdef __Linux__ |
129 |
+#ifdef __Linux__ |
122 |
static char *skipspace(char *s) |
130 |
static char *skipspace(char *s) |
123 |
{ |
131 |
{ |
124 |
while (isspace(*s)) |
132 |
while (isspace(*s)) |
125 |
@@ -484,6 +558,7 @@ |
133 |
++s; |
126 |
} |
134 |
return s; |
127 |
return skipspace(s); |
|
|
128 |
} |
135 |
} |
129 |
+#endif |
136 |
+#endif |
130 |
|
137 |
|
131 |
static void dump_mce_final(struct mce *m, char *symbol, int missing, int recordlen, |
138 |
static char *skip_syslog(char *s) |
132 |
int dseen) |
139 |
{ |
133 |
@@ -507,6 +582,7 @@ |
140 |
@@ -667,6 +748,7 @@ static int match_patterns(char *s, char |
134 |
recordlen = endof_field(struct mce, f) |
141 |
recordlen = endof_field(struct mce, f) |
135 |
|
142 |
|
136 |
/* Decode ASCII input for fatal messages */ |
143 |
/* Decode ASCII input for fatal messages */ |
Lines 138-144
Link Here
|
138 |
static void decodefatal(FILE *inf) |
145 |
static void decodefatal(FILE *inf) |
139 |
{ |
146 |
{ |
140 |
struct mce m; |
147 |
struct mce m; |
141 |
@@ -651,6 +727,227 @@ |
148 |
@@ -877,6 +959,227 @@ restart: |
142 |
if (data) |
149 |
if (data) |
143 |
dump_mce_final(&m, symbol, missing, recordlen, disclaimer_seen); |
150 |
dump_mce_final(&m, symbol, missing, recordlen, disclaimer_seen); |
144 |
} |
151 |
} |
Lines 366-372
Link Here
|
366 |
|
373 |
|
367 |
static void remove_pidfile(void) |
374 |
static void remove_pidfile(void) |
368 |
{ |
375 |
{ |
369 |
@@ -709,6 +1006,10 @@ |
376 |
@@ -941,6 +1244,10 @@ void usage(void) |
370 |
" mcelog [options] --ascii < log\n" |
377 |
" mcelog [options] --ascii < log\n" |
371 |
" mcelog [options] --ascii --file log\n" |
378 |
" mcelog [options] --ascii --file log\n" |
372 |
"Decode machine check ASCII output from kernel logs\n" |
379 |
"Decode machine check ASCII output from kernel logs\n" |
Lines 374-385
Link Here
|
374 |
+" mcelog [options] -M vmcore -N kernel\n" |
381 |
+" mcelog [options] -M vmcore -N kernel\n" |
375 |
+"Decode machine check error records from kernel crashdump.\n" |
382 |
+"Decode machine check error records from kernel crashdump.\n" |
376 |
+#endif |
383 |
+#endif |
|
|
384 |
"\n" |
377 |
"Options:\n" |
385 |
"Options:\n" |
378 |
"--cpu CPU Set CPU type CPU to decode (see below for valid types)\n" |
386 |
"--version Show the version of mcelog and exit\n" |
379 |
"--cpumhz MHZ Set CPU Mhz to decode time (output unreliable, not needed on new kernels)\n" |
387 |
@@ -1147,6 +1454,14 @@ static int modifier(int opt) |
380 |
@@ -889,6 +1190,14 @@ |
388 |
case O_IS_CPU_SUPPORTED: |
381 |
case O_CONFIG_FILE: |
389 |
check_only = 1; |
382 |
/* parsed in config.c */ |
|
|
383 |
break; |
390 |
break; |
384 |
+#ifdef __FreeBSD__ |
391 |
+#ifdef __FreeBSD__ |
385 |
+ case 'M': |
392 |
+ case 'M': |
Lines 392-409
Link Here
|
392 |
case 0: |
399 |
case 0: |
393 |
break; |
400 |
break; |
394 |
default: |
401 |
default: |
395 |
@@ -923,8 +1232,10 @@ |
402 |
@@ -1197,10 +1512,12 @@ static int combined_modifier(int opt) |
396 |
|
403 |
|
397 |
static void general_setup(void) |
404 |
static void general_setup(void) |
398 |
{ |
405 |
{ |
399 |
+#ifdef __Linux__ |
406 |
+#ifdef __Linux__ |
400 |
trigger_setup(); |
407 |
trigger_setup(); |
401 |
yellow_setup(); |
408 |
yellow_setup(); |
|
|
409 |
bus_setup(); |
410 |
unknown_setup(); |
402 |
+#endif |
411 |
+#endif |
403 |
config_cred("global", "run-credentials", &runcred); |
412 |
config_cred("global", "run-credentials", &runcred); |
404 |
if (config_bool("global", "filter-memory-errors") == 1) |
413 |
if (config_bool("global", "filter-memory-errors") == 1) |
405 |
filter_memory_errors = 1; |
414 |
filter_memory_errors = 1; |
406 |
@@ -947,6 +1258,7 @@ |
415 |
@@ -1223,6 +1540,7 @@ static void drop_cred(void) |
407 |
} |
416 |
} |
408 |
} |
417 |
} |
409 |
|
418 |
|
Lines 411-417
Link Here
|
411 |
static void process(int fd, unsigned recordlen, unsigned loglen, char *buf) |
420 |
static void process(int fd, unsigned recordlen, unsigned loglen, char *buf) |
412 |
{ |
421 |
{ |
413 |
int i; |
422 |
int i; |
414 |
@@ -987,6 +1299,173 @@ |
423 |
@@ -1275,6 +1593,173 @@ static void process(int fd, unsigned rec |
415 |
if (finish) |
424 |
if (finish) |
416 |
exit(0); |
425 |
exit(0); |
417 |
} |
426 |
} |
Lines 585-591
Link Here
|
585 |
|
594 |
|
586 |
static void noargs(int ac, char **av) |
595 |
static void noargs(int ac, char **av) |
587 |
{ |
596 |
{ |
588 |
@@ -1045,22 +1524,30 @@ |
597 |
@@ -1333,12 +1818,14 @@ struct mcefd_data { |
589 |
char *buf; |
598 |
char *buf; |
590 |
}; |
599 |
}; |
591 |
|
600 |
|
Lines 598-626
Link Here
|
598 |
} |
607 |
} |
599 |
+#endif |
608 |
+#endif |
600 |
|
609 |
|
|
|
610 |
static void handle_sigusr1(int sig) |
611 |
{ |
612 |
@@ -1347,13 +1834,18 @@ static void handle_sigusr1(int sig) |
613 |
|
601 |
int main(int ac, char **av) |
614 |
int main(int ac, char **av) |
602 |
{ |
615 |
{ |
603 |
+#ifdef __Linux__ |
616 |
+#ifdef __Linux__ |
604 |
struct mcefd_data d = {}; |
617 |
struct mcefd_data d = {}; |
605 |
- int opt; |
618 |
- int opt; |
606 |
int fd; |
619 |
int fd; |
|
|
620 |
- |
607 |
+#endif |
621 |
+#endif |
608 |
+ int opt; |
622 |
+ int opt; |
609 |
|
|
|
610 |
parse_config(av); |
623 |
parse_config(av); |
611 |
|
624 |
|
612 |
+#ifdef __FreeBSD__ |
625 |
+#ifdef __FreeBSD |
613 |
+ while ((opt = getopt_long(ac, av, "M:N:", options, NULL)) != -1) { |
626 |
+ while ((opt = getopt_long(ac, av, "M:N:", options, NULL)) != -1) { |
614 |
+#else |
627 |
+#else |
615 |
while ((opt = getopt_long(ac, av, "", options, NULL)) != -1) { |
628 |
while ((opt = getopt_long(ac, av, "", options, NULL)) != -1) { |
616 |
+#endif |
629 |
+#endif |
617 |
if (opt == '?') { |
630 |
if (opt == '?') { |
618 |
usage(); |
631 |
usage(); |
619 |
} else if (combined_modifier(opt) > 0) { |
632 |
} else if (combined_modifier(opt) > 0) { |
620 |
@@ -1080,13 +1567,21 @@ |
633 |
@@ -1375,11 +1867,13 @@ int main(int ac, char **av) |
621 |
} else if (opt == 0) |
|
|
622 |
break; |
623 |
} |
634 |
} |
|
|
635 |
|
636 |
/* before doing anything else let's see if the CPUs are supported */ |
637 |
+#ifdef __Linux__ |
638 |
if (!cpu_forced && !is_cpu_supported()) { |
639 |
if (!check_only) |
640 |
fprintf(stderr, "CPU is unsupported\n"); |
641 |
exit(1); |
642 |
} |
643 |
+#endif |
644 |
if (check_only) |
645 |
exit(0); |
646 |
|
647 |
@@ -1398,13 +1892,21 @@ int main(int ac, char **av) |
648 |
} |
649 |
|
650 |
modifier_finish(); |
624 |
+#ifdef __Linux__ |
651 |
+#ifdef __Linux__ |
625 |
if (av[optind]) |
652 |
if (av[optind]) |
626 |
logfn = av[optind++]; |
653 |
logfn = av[optind++]; |
Lines 639-658
Link Here
|
639 |
fd = open(logfn, O_RDONLY); |
666 |
fd = open(logfn, O_RDONLY); |
640 |
if (fd < 0) { |
667 |
if (fd < 0) { |
641 |
if (ignore_nodev) |
668 |
if (ignore_nodev) |
642 |
@@ -1101,24 +1596,39 @@ |
669 |
@@ -1419,27 +1921,44 @@ int main(int ac, char **av) |
643 |
err("MCE_GET_LOG_LEN"); |
670 |
err("MCE_GET_LOG_LEN"); |
644 |
|
671 |
|
645 |
d.buf = xalloc(d.recordlen * d.loglen); |
672 |
d.buf = xalloc(d.recordlen * d.loglen); |
646 |
+#endif |
673 |
+#endif |
647 |
if (daemon_mode) { |
674 |
if (daemon_mode) { |
648 |
check_cpu(); |
675 |
prefill_memdb(do_dmi); |
649 |
prefill_memdb(); |
|
|
650 |
if (!do_dmi) |
676 |
if (!do_dmi) |
651 |
closedmi(); |
677 |
closedmi(); |
652 |
server_setup(); |
678 |
server_setup(); |
653 |
+#ifdef __Linux__ |
679 |
+#ifdef __Linux__ |
654 |
page_setup(); |
680 |
page_setup(); |
655 |
+#endif |
681 |
+#endif |
|
|
682 |
if (imc_log) |
683 |
set_imc_log(cputype); |
656 |
drop_cred(); |
684 |
drop_cred(); |
657 |
+#ifdef __Linux__ |
685 |
+#ifdef __Linux__ |
658 |
register_pollcb(fd, POLLIN, process_mcefd, &d); |
686 |
register_pollcb(fd, POLLIN, process_mcefd, &d); |
Lines 661-666
Link Here
|
661 |
err("daemon"); |
689 |
err("daemon"); |
662 |
if (pidfile) |
690 |
if (pidfile) |
663 |
write_pidfile(); |
691 |
write_pidfile(); |
|
|
692 |
signal(SIGUSR1, handle_sigusr1); |
693 |
+#ifdef __Linux__ |
694 |
event_signal(SIGUSR1); |
695 |
+#endif |
664 |
eventloop(); |
696 |
eventloop(); |
665 |
} else { |
697 |
} else { |
666 |
+#ifdef __Linux__ |
698 |
+#ifdef __Linux__ |