From d8862fba3550e57c7d91cd2830b0bf6df6a4192a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Martin=20Mare=C5=A1?= Date: Sun, 5 Apr 2026 18:38:32 +0200 Subject: [PATCH] dump: Support `lspci -F -` for stdin 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 . --- lib/dump.c | 17 +++++++++++------ lspci.man | 4 ++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/dump.c b/lib/dump.c index db11168..2e1eb4b 100644 --- a/lib/dump.c +++ b/lib/dump.c @@ -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); diff --git a/lspci.man b/lspci.man index fb7c770..09eb3ad 100644 --- a/lspci.man +++ b/lspci.man @@ -204,6 +204,10 @@ Use direct hardware access via Intel configuration mechanism 2. .B -F 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. -- 2.47.3