diff --git a/debian/changelog b/debian/changelog index daabe98..bb921f7 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -fancon (0.23.1) UNRELEASED; urgency=low +fancon (0.23.2) UNRELEASED; urgency=low * Initial release. Closes: #00000 diff --git a/src/Client.cpp b/src/Client.cpp index 1ae1ec2..624fbae 100644 --- a/src/Client.cpp +++ b/src/Client.cpp @@ -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()) @@ -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); } } diff --git a/src/DellSMM.cpp b/src/DellSMM.cpp index ca396cb..e476fed 100644 --- a/src/DellSMM.cpp +++ b/src/DellSMM.cpp @@ -3,31 +3,25 @@ using namespace fc; namespace fc::SMM { -short smm_found{-1}; -InitState init_state{InitState::NOT_INITIALIZED}; +optional 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) { @@ -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 ®s) { diff --git a/src/DellSMM.hpp b/src/DellSMM.hpp index 33a944c..45b61d5 100644 --- a/src/DellSMM.hpp +++ b/src/DellSMM.hpp @@ -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 smm_found, io_initialized; struct smm_regs { unsigned int eax; @@ -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, @@ -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