]> mj.ucw.cz Git - pciutils.git/commitdiff
dump: Support `lspci -F -` for stdin
authorMartin Mareš <mj@ucw.cz>
Sun, 5 Apr 2026 16:38:32 +0000 (18:38 +0200)
committerMartin Mareš <mj@ucw.cz>
Sun, 5 Apr 2026 16:38:32 +0000 (18:38 +0200)
It can be useful to pipe raw config registers (lspci -x) from one system
to another, so the latter system can do the parsing (lspci -vv -F ...).
For example, one might do this if the former has a more limited / older
version of lspci. Today, one has to write the contents to a file.

Support stdin via "-", so it's easier to run it through a pipeline, such
as:

  ssh ${remote_host} old_lspci -xxx | new_lspci -vv -F -

A dash (-) is a common convention used by many other tools. If one
really expected to access a file named "-", one can use "./-" or similar
to disambiguate.

Based on a patch by Brian Norris <briannorris@chromium.org>.

lib/dump.c
lspci.man

index db111685c6340e49d8d816bc614ca3c624cf93eb..2e1eb4b5421b0003f21e8c7632a41971e9ba17ff 100644 (file)
@@ -122,16 +122,21 @@ static void
 dump_init(struct pci_access *a)
 {
   char *name = pci_get_param(a, "dump.name");
-  FILE *f;
+  const char *err;
 
   if (!name)
     a->error("dump: File name not given.");
-  if (!(f = fopen(name, "r")))
-    a->error("dump: Cannot open %s: %s", name, strerror(errno));
 
-  const char *err = dump_parse(a, f);
-
-  fclose(f);
+  if (!strcmp(name, "-"))
+    err = dump_parse(a, stdin);
+  else
+    {
+      FILE *f = fopen(name, "r");
+      if (!f)
+       a->error("dump: Cannot open %s: %s", name, strerror(errno));
+      err = dump_parse(a, f);
+      fclose(f);
+    }
 
   if (err)
     a->error("dump: %s", err);
index fb7c77017232b8a9c0c97393ef29bd42f7cd87a6..09eb3adf7e225793dbf8f9827b71ed67062d8db6 100644 (file)
--- a/lspci.man
+++ b/lspci.man
@@ -204,6 +204,10 @@ Use direct hardware access via Intel configuration mechanism 2.
 .B -F <file>
 Instead of accessing real hardware, read the list of devices and values of their
 configuration registers from the given file produced by an earlier run of lspci -x.
+If
+.I file
+is a single dash (\fB-\fP), read the contents from stdin.
+.IP
 This is very useful for analysis of user-supplied bug reports, because you can display
 the hardware configuration in any way you want without disturbing the user with
 requests for more dumps.