fix: sudo dmidecode fallback when running without root
Without root, dmidecode exits 0 but outputs only a header comment with no Handle blocks (DMI tables are root-only in sysfs). The previous empty-string check never triggered the sudo retry. Now checks for the presence of 'Handle ' lines: if absent, retries transparently with sudo. Users with passwordless sudo get full hardware detail (CPU slots, memory sticks/slots, cache, voltage) without needing to explicitly invoke sudo themselves. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
69113c1ea7
commit
29440b68a9
2 changed files with 4 additions and 0 deletions
Binary file not shown.
|
|
@ -41,6 +41,10 @@ Discovery::parse_dmi(const std::string& type_num) {
|
|||
return {}; // dmidecode not available on macOS; callers check __APPLE__
|
||||
#else
|
||||
std::string output = run_cmd("dmidecode -t " + type_num + " 2>/dev/null");
|
||||
// Without root, dmidecode outputs only a header comment with no Handle blocks.
|
||||
// If no "Handle " lines appear, retry transparently with sudo.
|
||||
if (output.find("Handle ") == std::string::npos)
|
||||
output = run_cmd("sudo dmidecode -t " + type_num + " 2>/dev/null");
|
||||
if (output.empty()) return {};
|
||||
|
||||
std::vector<std::map<std::string, std::string>> result;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue