Skip to content

Commit

Permalink
✨ Handle signals to guarantee fans are set back to auto
Browse files Browse the repository at this point in the history
Closes #70
  • Loading branch information
mmstick committed May 21, 2019
1 parent 1d361ba commit 33fe432
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ authors = ["Jeremy Soller <jackpot51@gmail.com>"]
edition = "2018"

[dependencies]
dbus = "=0.6.2"
dbus = "0.6"
libc = "0.2"
clap = "2.32.0"
clap = "2.32"
log = "0.4.3"
fern = "0.5.6"
intel-pstate = "0.2.0"
sysfs-class = { git = "https://github.com/pop-os/sysfs-class" }
err-derive = "0.1.5"


[build-dependencies]
vergen = "0.1.1"
24 changes: 23 additions & 1 deletion src/daemon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ mod profiles;

use self::profiles::*;

static CONTINUE: AtomicBool = AtomicBool::new(true);

fn signal_handling() {
extern "C" fn handler(signal: libc::c_int) {
info!("caught signal: {}", signal);
CONTINUE.store(false, Ordering::SeqCst);
}

unsafe fn signal(signal: libc::c_int) { libc::signal(signal, handler as libc::sighandler_t); }

unsafe {
signal(libc::SIGINT);
signal(libc::SIGHUP);
signal(libc::SIGTERM);
signal(libc::SIGKILL);
}
}

// Disabled by default because some systems have quirky ACPI tables that fail to resume from
// suspension.
static PCI_RUNTIME_PM: AtomicBool = AtomicBool::new(false);
Expand Down Expand Up @@ -124,6 +142,7 @@ impl Power for PowerDaemon {
}

pub fn daemon() -> Result<(), String> {
signal_handling();
let pci_runtime_pm = std::env::var("S76_POWER_PCI_RUNTIME_PM").ok().map_or(false, |v| v == "1");

info!(
Expand Down Expand Up @@ -262,7 +281,7 @@ pub fn daemon() -> Result<(), String> {
let mut last = hpd();

info!("Handling dbus requests");
loop {
while CONTINUE.load(Ordering::SeqCst) {
c.incoming(1000).next();

if let Ok(ref fan_daemon) = fan_daemon_res {
Expand All @@ -286,4 +305,7 @@ pub fn daemon() -> Result<(), String> {
}
}
}

info!("daemon exited from loop");
Ok(())
}

0 comments on commit 33fe432

Please sign in to comment.