From b3acafc0906af18242ceac16d835466fe6784a15 Mon Sep 17 00:00:00 2001 From: shy Date: Thu, 22 Apr 2021 10:59:13 +0200 Subject: [PATCH] Move signal handling to end of main loop. --- src/lib.rs | 61 +++++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e001f58..b9ba424 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -78,36 +78,6 @@ pub fn run( // Main loop entry. 'main: loop { - // Process received signals. - for signal in signals.pending() { - match signal { - // Suspend execution on SIGTSTP. - SIGTSTP => suspend(&mut stdout)?, - // Continuing after SIGTSTP or SIGSTOP. - SIGCONT => { - restore_after_suspend(&mut stdout)?; - force_redraw = true; - } - SIGWINCH => layout.schedule_recalc(), - // Exit main loop on SIGTERM and SIGINT. - SIGTERM | SIGINT => break 'main, - // Reset clock on SIGUSR1. - SIGUSR1 => { - clock.reset(); - alarm_roster.reset_all(); - layout.schedule_recalc(); - force_redraw = true; - } - // (Un-)Pause clock on SIGUSR2. - SIGUSR2 => { - clock.toggle(); - force_redraw = true; - } - // We didn't register anything else. - _ => unreachable!(), - } - } - // Update elapsed time. let elapsed = if clock.paused { clock.elapsed @@ -340,6 +310,37 @@ pub fn run( } } } + + // Process received signals. + for signal in signals.pending() { + match signal { + // Suspend execution on SIGTSTP. + SIGTSTP => suspend(&mut stdout)?, + // Continuing after SIGTSTP or SIGSTOP. + SIGCONT => { + restore_after_suspend(&mut stdout)?; + force_redraw = true; + } + SIGWINCH => layout.schedule_recalc(), + // Exit main loop on SIGTERM and SIGINT. + SIGTERM | SIGINT => break 'main, + // Reset clock on SIGUSR1. + SIGUSR1 => { + clock.reset(); + alarm_roster.reset_all(); + layout.schedule_recalc(); + force_redraw = true; + } + // (Un-)Pause clock on SIGUSR2. + SIGUSR2 => { + clock.toggle(); + force_redraw = true; + } + // We didn't register anything else. + _ => unreachable!(), + } + } + } // Main loop exited. Clear screen and restore cursor.