]> jfr.im git - irc/hexchat/hexchat.git/commitdiff
sysinfo: Avoid libpci crash when pci not available
authorPatrick Griffis <redacted>
Sat, 18 Nov 2017 05:14:13 +0000 (00:14 -0500)
committerPatrick Griffis <redacted>
Sat, 18 Nov 2017 05:22:48 +0000 (00:22 -0500)
Turns out libpci is an awful library that on any error calls
exit() and has no way of indicating an error otherwise...

plugins/sysinfo/unix/pci.c

index a887245c8491b9664b2ba0dcce9dcb5cca2e111c..10addf6fbb97aabb7da1fa97935b0c41410e8dc2 100644 (file)
@@ -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);
 }