File: is-cpu-supported.patch

package info (click to toggle)
mcelog 104-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 996 kB
  • ctags: 1,508
  • sloc: ansic: 7,739; sh: 481; makefile: 87
file content (91 lines) | stat: -rw-r--r-- 2,590 bytes parent folder | download
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
Description: Add --is-cpu-supported command line option
 When this option is provided, mcelog always exits silently after checking
 whether the CPU is supported. The return code is 0 if the CPU is supported,
 1 otherwise. This is intended for use in scripts that need to guard against
 starting the daemon on an unsupported platform.
Author: Sergio Gelato <Sergio.Gelato@astro.su.se>
Origin: vendor, https://bugs.launchpad.net/debian/+source/mcelog/+bug/1279293
Bug-Debian: https://bugs.debian.org/738927
Bug-Ubuntu: https://bugs.launchpad.net/debian/+source/mcelog/+bug/1279293
Last-Update: 2014-10-15

--- a/mcelog.c
+++ b/mcelog.c
@@ -83,6 +83,7 @@
 static char *logfile;
 static int debug_numerrors;
 int imc_log = -1;
+static int check_only = 0;
 
 static int is_cpu_supported(void);
 
@@ -930,6 +931,7 @@
 "--num-errors N      Only process N errors (for testing)\n"
 "--pidfile file	     Write pid of daemon into file\n"
 "--no-imc-log	     Disable extended iMC logging\n"
+"--is-cpu-supported  Exit with return code indicating whether the CPU is supported\n"
 		);
 	diskdb_usage();
 	print_cputypes();
@@ -964,6 +966,7 @@
 	O_PIDFILE,
 	O_DEBUG_NUMERRORS,
 	O_NO_IMC_LOG,
+	O_IS_CPU_SUPPORTED,
 };
 
 static struct option options[] = {
@@ -997,6 +1000,7 @@
 	{ "pidfile", 1, NULL, O_PIDFILE },
 	{ "debug-numerrors", 0, NULL, O_DEBUG_NUMERRORS }, /* undocumented: for testing */
 	{ "no-imc-log", 0, NULL, O_NO_IMC_LOG },
+	{ "is-cpu-supported", 0, NULL, O_IS_CPU_SUPPORTED },
 	DISKDB_OPTIONS
 	{}
 };
@@ -1104,6 +1108,9 @@
 	case O_NO_IMC_LOG:
 		imc_log = 0;
 		break;
+	case O_IS_CPU_SUPPORTED:
+		check_only = 1;
+		break;
 	case 0:
 		break;
 	default:
@@ -1321,9 +1328,12 @@
 
 	/* before doing anything else let's see if the CPUs are supported */
 	if (!cpu_forced && !is_cpu_supported()) {
-		fprintf(stderr, "CPU is unsupported\n");
+		if (!check_only)
+			fprintf(stderr, "CPU is unsupported\n");
 		exit(1);
 	}
+	if (check_only)
+		exit(0);
 
 	/* If the user didn't tell us not to use iMC logging, check if CPU supports it */
 	if (imc_log == -1) {
--- a/mcelog.8
+++ b/mcelog.8
@@ -17,6 +17,8 @@
 .\".br
 .\"mcelog [options] \-\-dump-memory[=locator]
 .br
+mcelog [options] \-\-is\-cpu\-supported
+.br
 mcelog \-\-version
 .SH DESCRIPTION
 X86 CPUs report errors detected by the CPU as
@@ -75,6 +77,10 @@
 so the output should be always saved somewhere and mcelog
 not run in uncontrolled ways.
 
+When invoked with the
+.I \-\-is\-cpu\-supported
+option mcelog exits with code 0 if the current CPU is supported, 1 otherwise.
+
 .SH OPTIONS
 When the 
 .B \-\-syslog