瀏覽代碼

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.
Liav A 3 年之前
父節點
當前提交
cb900006b9
共有 2 個文件被更改,包括 10 次插入3 次删除
  1. 5 0
      Base/usr/share/man/man8/lspci.md
  2. 5 3
      Userland/Utilities/lspci.cpp

+ 5 - 0
Base/usr/share/man/man8/lspci.md

@@ -13,6 +13,11 @@ $ lspci
 lspci is a utility for displaying information about PCI buses in the system
 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.
 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
 ## Files
 
 
 * `/sys/bus/pci` - source of the PCI devices list.
 * `/sys/bus/pci` - source of the PCI devices list.

+ 5 - 3
Userland/Utilities/lspci.cpp

@@ -45,9 +45,6 @@ static u32 convert_sysfs_value_to_uint(String const& value)
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 ErrorOr<int> serenity_main(Main::Arguments arguments)
 {
 {
     TRY(Core::System::pledge("stdio rpath"));
     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;
     Core::ArgsParser args_parser;
     args_parser.set_general_help("List PCI devices.");
     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.add_option(flag_verbose, "Show verbose info on devices", "verbose", 'v');
     args_parser.parse(arguments);
     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;
     auto const format = flag_show_numerical ? format_numerical : format_textual;
 
 
     RefPtr<PCIDB::Database> db;
     RefPtr<PCIDB::Database> db;