Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
Fixed requiring root to view help
Browse files Browse the repository at this point in the history
Refactored DellSMM

Signed-off-by: Hayden Briese <[email protected]>
  • Loading branch information
hbriese committed Aug 14, 2020
1 parent ad5ea79 commit a26acd1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 36 deletions.
2 changes: 1 addition & 1 deletion debian/changelog
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fancon (0.23.1) UNRELEASED; urgency=low
fancon (0.23.2) UNRELEASED; urgency=low

* Initial release. Closes: #00000

Expand Down
15 changes: 7 additions & 8 deletions src/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@ fc::Client::Client() {
}

void fc::Client::run(Args &args) {
if (args.help) {
print_help(args.config.value);
return;
}

if (!connected(1000)) {
if ((args.status || args.disable || args.test || args.reload ||
args.stop_service || args.nv_init || args.sysinfo) &&
!connected(1000)) {
log_service_unavailable();
return;
}

if (args.status) {
if (args.help) {
print_help(args.config.value);
} else if (args.status) {
status();
} else if (args.enable) {
if (args.enable.has_value())
Expand Down Expand Up @@ -55,7 +54,7 @@ void fc::Client::run(Args &args) {
if (answer == 'y') {
test(args.force);
}
} else { // else, excluding help which has already run
} else {
print_help(args.config.value);
}
}
Expand Down
35 changes: 13 additions & 22 deletions src/DellSMM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,25 @@
using namespace fc;

namespace fc::SMM {
short smm_found{-1};
InitState init_state{InitState::NOT_INITIALIZED};
optional<bool> smm_found = nullopt, io_initialized = nullopt;
} // namespace fc::SMM

bool SMM::found() {
if (smm_found == 0 || smm_found == 1)
return smm_found;
if (smm_found)
return *smm_found;

for (const auto c : {SMM::SMM_GET_DELL_SIG_1, SMM::SMM_GET_DELL_SIG_2}) {
for (const auto sig : {SMM::SMM_GET_DELL_SIG_1, SMM::SMM_GET_DELL_SIG_2}) {
struct smm_regs regs {};
regs.eax = c;
regs.eax = sig;

if (!i8k_smm(regs)) {
smm_found = 0;
return false;
}
if (!i8k_smm(regs))
return *smm_found = false;

if (regs.eax == SMM::DIAG_SIG && regs.edx == SMM::DELL_SIG) {
smm_found = 1;
return true;
}
if (regs.eax == SMM::DIAG_SIG && regs.edx == SMM::DELL_SIG)
return *smm_found = true;
}

smm_found = 0;
return false;
return *smm_found = false;
}

bool SMM::is_smm_dell(const string_view &sensor_chip_name) {
Expand Down Expand Up @@ -71,13 +65,10 @@ int SMM::fan_status(int fan) {
//}

bool SMM::init_ioperms() {
if (SMM::init_state == InitState::NOT_INITIALIZED) {
init_state = (ioperm(0xb2, 4, 1) == 0 && ioperm(0x84, 4, 1) == 0)
? InitState::SUCCESSFUL
: InitState::FAILED;
}
if (!SMM::io_initialized)
*io_initialized = ioperm(0xb2, 4, 1) == 0 && ioperm(0x84, 4, 1) == 0;

return SMM::init_state == InitState::SUCCESSFUL;
return *SMM::io_initialized;
}

bool SMM::i8k_smm(smm_regs &regs) {
Expand Down
8 changes: 3 additions & 5 deletions src/DellSMM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
// https://github.com/torvalds/linux/blob/master/drivers/hwmon/dell-smm-hwmon.c
// And Clopez dellfan https://github.com/clopez/dellfan/blob/master/dellfan.c
namespace fc::SMM {
extern short smm_found;

enum class InitState { NOT_INITIALIZED, SUCCESSFUL, FAILED } extern init_state;
extern optional<bool> smm_found, io_initialized;

struct smm_regs {
unsigned int eax;
Expand All @@ -23,7 +21,7 @@ struct smm_regs {
unsigned int edi __attribute__((packed));
};

enum Cmd {
enum Cmd : unsigned int {
SMM_SET_FAN = 0x01a3,
SMM_GET_FAN = 0x00a3,
SMM_GET_SPEED = 0x02a3,
Expand All @@ -42,7 +40,7 @@ enum Cmd {
SMM_GET_DELL_SIG_2 = 0xffa3
};

enum Result {
enum Result : unsigned int {
DELL_SIG = 0x44454C4C,
DIAG_SIG = 0x44494147,
FAN_NOT_FOUND = 0xff
Expand Down

0 comments on commit a26acd1

Please sign in to comment.