Skip to content

Commit

Permalink
Fix #63
Browse files Browse the repository at this point in the history
  • Loading branch information
jD91mZM2 committed Mar 16, 2021
1 parent d8d0d03 commit fd0a269
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
# `nix develop`
devShell = pkgs.mkShell {
buildInputs = buildInputs;
nativeBuildInputs = nativeBuildInputs ++ (with pkgs; [ rustc cargo gnome3.zenity ]);
nativeBuildInputs = nativeBuildInputs ++ (with pkgs; [ rustc cargo gnome3.zenity pipes ]);
};
});
}
6 changes: 6 additions & 0 deletions test-pid.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -euo pipefail

cargo run -- \
--timer 2 'pipes.sh' 'kill "$XIDLEHOOK_PID"'
9 changes: 5 additions & 4 deletions xidlehook-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,6 @@ where
);
max_sleep = cmp::min(max_sleep, remaining)
}
} else {
// No timer was enabled!
return Ok(Action::Forever);
}

if self.aborted {
Expand Down Expand Up @@ -414,7 +411,11 @@ where
}
}

Ok(Action::Sleep(max_sleep))
if max_sleep == Duration::from_secs(u64::MAX) {
Ok(Action::Forever)
} else {
Ok(Action::Sleep(max_sleep))
}
}

/// Runs a standard poll-sleep-repeat loop.
Expand Down
12 changes: 11 additions & 1 deletion xidlehook-core/src/timers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,17 @@ impl Timer for CmdTimer {

fn activate(&mut self) -> Result<()> {
if let Some(ref mut activation) = self.activation {
self.activation_child = Some(activation.spawn()?);
let child = activation.spawn()?;
let pid = child.id().to_string();

if let Some(ref mut abortion) = self.abortion {
abortion.env("XIDLEHOOK_PID", &pid);
}
if let Some(ref mut deactivation) = self.deactivation {
deactivation.env("XIDLEHOOK_PID", &pid);
}

self.activation_child = Some(child);
}
Ok(())
}
Expand Down

2 comments on commit fd0a269

@wavexx
Copy link

@wavexx wavexx commented on fd0a269 Mar 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm no expert in rust, but are you monitoring for SIGCHLD and unset the PID of the process when that terminates?

If the canceller is run after the activation process already terminated the PID is stale and could refer to a different process.

@jD91mZM2
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm no expert in rust, but are you monitoring for SIGCHLD and unset the PID of the process when that terminates?

If the canceller is run after the activation process already terminated the PID is stale and could refer to a different process.

I am monitoring for SIGCHLD at a different place to call wait and get rid of zombie processes. So you're right the PID could be stale. Crap. I have no idea how to hook that up to this code in the best way

Please sign in to comment.