Skip to content

Commit

Permalink
fix: panic on SIGHUP by closed /dev/tty
Browse files Browse the repository at this point in the history
This fixes a panic caused by the `SIGHUP` signal being sent to the
process after its controlling terminal closes. Handling `SIGHUP` isn't
necessary as we're not interested in whether the controlling terminal
closed, only in the fact that we need to terminate. `SIGTERM` will
always be sent as well so just react to that.
  • Loading branch information
ThomasFrans committed Oct 7, 2023
1 parent b27b067 commit ce37893
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use cursive::{Cursive, CursiveRunner};
use log::{error, info, trace};

#[cfg(unix)]
use signal_hook::{consts::SIGHUP, consts::SIGTERM, iterator::Signals};
use signal_hook::{consts::SIGTERM, iterator::Signals};

use crate::command::Command;
use crate::commands::CommandManager;
Expand Down Expand Up @@ -204,15 +204,14 @@ impl Application {
/// Start the application and run the event loop.
pub fn run(&mut self) -> Result<(), String> {
#[cfg(unix)]
let mut signals =
Signals::new([SIGTERM, SIGHUP]).expect("could not register signal handler");
let mut signals = Signals::new([SIGTERM]).expect("could not register signal handler");

// cursive event loop
while self.cursive.is_running() {
self.cursive.step();
#[cfg(unix)]
for signal in signals.pending() {
if signal == SIGTERM || signal == SIGHUP {
if signal == SIGTERM {
info!("Caught {}, cleaning up and closing", signal);
if let Some(data) = self.cursive.user_data::<UserData>().cloned() {
data.cmd.handle(&mut self.cursive, Command::Quit);
Expand Down

0 comments on commit ce37893

Please sign in to comment.