summary refs log tree commit diff stats
path: root/plugins/sysinfo/unix/pci.c
diff options
context:
space:
mode:
authorPatrick Griffis <tingping@tingping.se>2017-11-18 00:14:13 -0500
committerPatrick Griffis <tingping@tingping.se>2017-11-18 00:22:48 -0500
commit47b653cc7c981cb2a20dc2140c66d90b6f3088d0 (patch)
tree80695c0875021ca89c7911156454b46aebee8d69 /plugins/sysinfo/unix/pci.c
parentc6d9e26e2b35377cba33b0b9e8e30c371bdf68ba (diff)
sysinfo: Avoid libpci crash when pci not available
Turns out libpci is an awful library that on any error calls
exit() and has no way of indicating an error otherwise...
Diffstat (limited to 'plugins/sysinfo/unix/pci.c')
-rw-r--r--plugins/sysinfo/unix/pci.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/plugins/sysinfo/unix/pci.c b/plugins/sysinfo/unix/pci.c
index a887245c..10addf6f 100644
--- a/plugins/sysinfo/unix/pci.c
+++ b/plugins/sysinfo/unix/pci.c
@@ -92,6 +92,11 @@ int pci_find_by_class(u16 *class, char *vendor, char *device)
 	struct pci_dev *p;
 	int nomatch = 1;
 
+	/* libpci has no way to report errors it calls exit()
+	 * so we need to manually avoid potential failures like this one */
+	if (!g_file_test ("/proc/bus/pci", G_FILE_TEST_EXISTS))
+		return 1;
+
 	pacc = pci_alloc();
 	pci_filter_init(pacc, &filter);
 	pci_init(pacc);
@@ -161,6 +166,6 @@ void pci_find_fullname(char *fullname, char *vendor, char *device)
 	if (cardfound == 1)
 		g_snprintf(fullname, bsize, "%s %s", vendorname, devicename);
 	else
-		g_snprintf(fullname, bsize, "%s:%s", vendor, device);	
+		g_snprintf(fullname, bsize, "%s:%s", vendor, device);
 	fclose(fp);
 }