Blame SOURCES/pciutils-dir-d.patch

fd288c
diff -up pciutils-3.2.1/lib/names-parse.c.dird pciutils-3.2.1/lib/names-parse.c
fd288c
--- pciutils-3.2.1/lib/names-parse.c.dird	2012-12-06 17:05:14.000000000 +0100
fd288c
+++ pciutils-3.2.1/lib/names-parse.c	2014-01-03 18:12:22.856381553 +0100
454028
@@ -6,10 +6,13 @@
454028
  *	Can be freely distributed and used under the terms of the GNU GPL.
454028
  */
454028
 
454028
+#define _GNU_SOURCE
454028
 #include <stdio.h>
454028
 #include <stdlib.h>
454028
 #include <string.h>
454028
 #include <errno.h>
454028
+#include <dirent.h>
454028
+#include <libgen.h>
454028
 
454028
 #include "internal.h"
454028
 #include "names.h"
454028
@@ -82,7 +85,7 @@ static inline int id_white_p(int c)
454028
 }
454028
 
454028
 
454028
-static const char *id_parse_list(struct pci_access *a, pci_file f, int *lino)
454028
+static const char *id_parse_list(struct pci_access *a, pci_file f, int *lino, int flags)
454028
 {
454028
   char line[MAX_LINE];
454028
   char *p;
fd288c
@@ -207,7 +210,7 @@ static const char *id_parse_list(struct
454028
 	p++;
454028
       if (!*p)
454028
 	return parse_error;
454028
-      if (pci_id_insert(a, cat, id1, id2, id3, id4, p, SRC_LOCAL))
454028
+      if (pci_id_insert(a, cat, id1, id2, id3, id4, p, SRC_LOCAL) && flags)
454028
 	return "Duplicate entry";
454028
     }
454028
   return NULL;
454028
@@ -223,13 +226,14 @@ pci_load_name_list(struct pci_access *a)
454028
   pci_free_name_list(a);
454028
   a->id_load_failed = 1;
454028
   if (!(f = pci_open(a)))
454028
-    return 0;
454028
-  err = id_parse_list(a, f, &lino);
454028
+    return pci_new_load_name_list(a);
454028
+  err = id_parse_list(a, f, &lino, 0);
454028
   PCI_ERROR(f, err);
454028
   pci_close(f);
454028
   if (err)
454028
     a->error("%s at %s, line %d\n", err, a->id_file_name, lino);
454028
   a->id_load_failed = 0;
454028
+  pci_new_load_name_list(a);
454028
   return 1;
454028
 }
454028
 
454028
@@ -249,3 +253,49 @@ pci_set_name_list_path(struct pci_access
454028
   a->id_file_name = name;
454028
   a->free_id_name = to_be_freed;
454028
 }
454028
+int pci_new_load_name_list(struct pci_access *a)
454028
+{
454028
+  pci_file f;
454028
+  int lino, tempsize;
454028
+  const char *err;
454028
+  char *temp;
454028
+  char new_id_path[PATH_MAX+1] = {0,};
454028
+  DIR *pci_ids_dir;
454028
+  struct dirent *dp;
454028
+  
454028
+  strncpy(new_id_path, a->id_file_name, PATH_MAX);
454028
+  new_id_path[PATH_MAX] = 0;
454028
+  strncat(new_id_path, ".d/", PATH_MAX - strnlen(new_id_path, PATH_MAX));
454028
+  /* printf("new_id_path is %s\n", new_id_path); */
454028
+  pci_ids_dir = opendir(new_id_path); 
454028
+  if (pci_ids_dir == NULL)
454028
+    return 0;
454028
+
454028
+  do
454028
+    {
454028
+     if ((dp = readdir(pci_ids_dir)) != NULL)
454028
+       {
454028
+          if (! strcmp(dp->d_name, "..") || ! strcmp(dp->d_name, "."))
454028
+            continue;
454028
+          if (strstr(dp->d_name, ".ids")) 
454028
+            {
454028
+             tempsize = strnlen(new_id_path, PATH_MAX) + dp->d_reclen + 1;
454028
+             temp = malloc(tempsize);      /* This malloced memory is freed in the function pci_set_name_list_path() */ 
454028
+             memset(temp, 0, tempsize);
454028
+             strncpy(temp, new_id_path, (strnlen(new_id_path, PATH_MAX))+1);
454028
+             strncat(temp, dp->d_name, PATH_MAX - strnlen(temp, PATH_MAX));
454028
+             /* printf("Found file %s, processing it\n", temp); */
454028
+             pci_set_name_list_path(a, temp, 1);
454028
+             if (!(f = pci_open(a)))
454028
+               continue;
454028
+             err = id_parse_list(a, f, &lino, 0);
454028
+             PCI_ERROR(f, err);
454028
+             pci_close(f);
454028
+             if (err)
454028
+               a->error("%s at %s, line %d\n", err, a->id_file_name, lino);
454028
+            }
454028
+       }
454028
+    }while (dp != NULL);
454028
+  closedir(pci_ids_dir);
454028
+  return 1;
454028
+}   
fd288c
diff -up pciutils-3.2.1/lib/pci.h.dird pciutils-3.2.1/lib/pci.h
fd288c
--- pciutils-3.2.1/lib/pci.h.dird	2013-04-01 15:35:24.000000000 +0200
fd288c
+++ pciutils-3.2.1/lib/pci.h	2014-01-03 18:12:22.857381545 +0100
fd288c
@@ -223,6 +223,7 @@ int pci_load_name_list(struct pci_access
454028
 void pci_free_name_list(struct pci_access *a) PCI_ABI;	/* Called automatically by pci_cleanup() */
454028
 void pci_set_name_list_path(struct pci_access *a, char *name, int to_be_freed) PCI_ABI;
454028
 void pci_id_cache_flush(struct pci_access *a) PCI_ABI;
454028
+int pci_new_load_name_list(struct pci_access *a);
454028
 
454028
 enum pci_lookup_mode {
454028
   PCI_LOOKUP_VENDOR = 1,		/* Vendor name (args: vendorID) */