[PATCH][v2] lib: fwts_dump: add cpuinfo dump

Alex Hung alex.hung at canonical.com
Tue Jun 17 19:52:26 UTC 2014


When running fwts-live, it is sometimes difficult to analyze
results without cpu information. This patch dump cpuinfo
from /proc/cpuinfo.

Signed-off-by: Alex Hung <alex.hung at canonical.com>
---
 src/lib/src/fwts_dump.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/src/lib/src/fwts_dump.c b/src/lib/src/fwts_dump.c
index 8c59f57..33156c0 100644
--- a/src/lib/src/fwts_dump.c
+++ b/src/lib/src/fwts_dump.c
@@ -222,6 +222,33 @@ static int dump_readme(void)
 }
 
 /*
+ *  dump_cpuinfo()
+ *	read cpuinfo, dump to path/filename
+ */
+static int dump_cpuinfo(void)
+{
+	FILE *source, *target;
+	char buffer[1024];
+	size_t bytes;
+
+	if ((source = fopen("/proc/cpuinfo", "r")) == NULL)
+		return FWTS_ERROR;
+
+	if ((target = fopen("cpuinfo.log", "w")) == NULL) {
+		fclose(source);
+		return FWTS_ERROR;
+	}
+
+	while (0 < (bytes = fread(buffer, 1, sizeof(buffer), source)))
+		fwrite(buffer, 1, bytes, target);
+
+	fclose(source);
+	fclose(target);
+
+	return FWTS_OK;
+}
+
+/*
  *  fwts_dump_info()
  *	dump various system specific information:
  *	kernel log, dmidecode output, lspci output,
@@ -273,5 +300,10 @@ int fwts_dump_info(fwts_framework *fw)
 	} else
 		fprintf(stderr, "Need root privilege to dump ACPI tables.\n");
 
+	if (dump_cpuinfo() != FWTS_OK)
+		fprintf(stderr, "Failed to dump cpuinfo.\n");
+	else
+		printf("Dumping cpuinfo to cpuinfo.log\n");
+
 	return FWTS_OK;
 }
-- 
1.9.1




More information about the fwts-devel mailing list