]> mj.ucw.cz Git - pciutils.git/blobdiff - ls-kernel.c
lspci: Indent PCIe Capability DevCap2 & DevCtl2 correctly
[pciutils.git] / ls-kernel.c
index 15aa46ac083da890f5572998b2d9c989b411b546..ecacd0e65dce62080ef064797e7a60f7349fe780 100644 (file)
@@ -29,13 +29,7 @@ show_kernel_init(void)
   if (show_kernel_inited >= 0)
     return show_kernel_inited;
 
-  struct utsname uts;
-  if (uname(&uts) < 0)
-    die("uname() failed: %m");
-  char *name = alloca(64 + strlen(uts.release));
-  sprintf(name, "/lib/modules/%s", uts.release);
-
-  kmod_ctx = kmod_new(name, NULL);
+  kmod_ctx = kmod_new(NULL, NULL);
   if (!kmod_ctx)
     {
       fprintf(stderr, "lspci: Unable to initialize libkmod context\n");
@@ -196,19 +190,16 @@ match_pcimap(struct device *d, struct pcimap_entry *e)
 
 static const char *next_module(struct device *d)
 {
-  static struct pcimap_entry *current, *last_printed;
+  static struct pcimap_entry *current;
 
   if (!current)
-    {
-      current = pcimap_head;
-      last_printed = NULL;
-    }
+    current = pcimap_head;
   else
     current = current->next;
 
   while (current)
     {
-      if (match_pcimap(d, current) && (!last_printed || strcmp(last_printed->module, current->module)))
+      if (match_pcimap(d, current))
        return current->module;
       current = current->next;
     }
@@ -257,6 +248,25 @@ find_driver(struct device *d, char *buf)
     return buf;
 }
 
+static const char *
+next_module_filtered(struct device *d)
+{
+  static char prev_module[256];
+  const char *module;
+
+  while (module = next_module(d))
+    {
+      if (strcmp(module, prev_module))
+       {
+         strncpy(prev_module, module, sizeof(prev_module));
+         prev_module[sizeof(prev_module) - 1] = 0;
+         return module;
+       }
+    }
+  prev_module[0] = 0;
+  return NULL;
+}
+
 void
 show_kernel(struct device *d)
 {
@@ -270,7 +280,7 @@ show_kernel(struct device *d)
     return;
 
   int cnt = 0;
-  while (module = next_module(d))
+  while (module = next_module_filtered(d))
     printf("%s %s", (cnt++ ? "," : "\tKernel modules:"), module);
   if (cnt)
     putchar('\n');
@@ -288,7 +298,7 @@ show_kernel_machine(struct device *d)
   if (!show_kernel_init())
     return;
 
-  while (module = next_module(d))
+  while (module = next_module_filtered(d))
     printf("Module:\t%s\n", module);
 }