Utilities/lspci: Don't unveil /res/pci.ids if not asked to resolve IDs

I tested the grub image under VirtualBox and it appeared that the image
didn't have pci.ids file included in the /res directory. In that case it
would be expected that lspci can still function correctly if the -n
parameter is passed, but then the unveil syscall failed because the file
didn't exist.

To cope with this, we should allow lspci to work without the pci.ids
file being present at the filesystem, so let's not unveil this file if
the -n parameter is passed.
This commit is contained in:
Liav A 2022-07-15 14:30:39 +03:00 committed by Linus Groh
parent a857b6297a
commit cb900006b9
Notes: sideshowbarker 2024-07-17 08:47:43 +09:00
2 changed files with 10 additions and 3 deletions

View file

@ -13,6 +13,11 @@ $ lspci
lspci is a utility for displaying information about PCI buses in the system
and devices connected to them. It shows a brief list of devices.
## Options
* `-n`, `--numerical`: Don't try to resolve numerical PCI IDs. This is useful when
there is a need to see the actual PCI IDs, or if `/res/pci.ids` file is not available.
## Files
* `/sys/bus/pci` - source of the PCI devices list.

View file

@ -45,9 +45,6 @@ static u32 convert_sysfs_value_to_uint(String const& value)
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
TRY(Core::System::pledge("stdio rpath"));
TRY(Core::System::unveil("/res/pci.ids", "r"));
TRY(Core::System::unveil("/sys/bus/pci", "r"));
TRY(Core::System::unveil(nullptr, nullptr));
Core::ArgsParser args_parser;
args_parser.set_general_help("List PCI devices.");
@ -55,6 +52,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
args_parser.add_option(flag_verbose, "Show verbose info on devices", "verbose", 'v');
args_parser.parse(arguments);
if (!flag_show_numerical)
TRY(Core::System::unveil("/res/pci.ids", "r"));
TRY(Core::System::unveil("/sys/bus/pci", "r"));
TRY(Core::System::unveil(nullptr, nullptr));
auto const format = flag_show_numerical ? format_numerical : format_textual;
RefPtr<PCIDB::Database> db;