@@ -13,6 +13,36 @@ use crate::paging::PagingMode;
1313#[ cfg( feature = "paging" ) ]
1414use crate :: wrapping:: WrappingMode ;
1515
16+ #[ cfg( all( unix, feature = "paging" ) ) ]
17+ use std:: sync:: atomic:: AtomicBool ;
18+ #[ cfg( all( unix, feature = "paging" ) ) ]
19+ use std:: sync:: Arc ;
20+ #[ cfg( all( unix, feature = "paging" ) ) ]
21+ struct IgnoreSigint {
22+ _handle : signal_hook:: SigId ,
23+ }
24+
25+ #[ cfg( all( unix, feature = "paging" ) ) ]
26+ impl IgnoreSigint {
27+ fn new ( ) -> Self {
28+ // No-op SIGINT handler prevents pager process termination
29+ let handle = signal_hook:: flag:: register (
30+ signal_hook:: consts:: SIGINT ,
31+ Arc :: new ( AtomicBool :: new ( false ) ) ,
32+ )
33+ . expect ( "failed to ignore SIGINT" ) ;
34+
35+ Self { _handle : handle }
36+ }
37+ }
38+
39+ #[ cfg( feature = "paging" ) ]
40+ pub struct PagerProc {
41+ child : Child ,
42+ #[ cfg( unix) ]
43+ _sigint_guard : IgnoreSigint ,
44+ }
45+
1646#[ cfg( feature = "paging" ) ]
1747pub struct BuiltinPager {
1848 pager : minus:: Pager ,
@@ -50,10 +80,9 @@ enum SingleScreenAction {
5080 Nothing ,
5181}
5282
53- #[ derive( Debug ) ]
5483pub enum OutputType {
5584 #[ cfg( feature = "paging" ) ]
56- Pager ( Child ) ,
85+ Pager ( PagerProc ) ,
5786 #[ cfg( feature = "paging" ) ]
5887 BuiltinPager ( BuiltinPager ) ,
5988 Stdout ( io:: Stdout ) ,
@@ -166,7 +195,13 @@ impl OutputType {
166195
167196 Ok ( p. stdin ( Stdio :: piped ( ) )
168197 . spawn ( )
169- . map ( OutputType :: Pager )
198+ . map ( |child| {
199+ OutputType :: Pager ( PagerProc {
200+ child,
201+ #[ cfg( unix) ]
202+ _sigint_guard : IgnoreSigint :: new ( ) ,
203+ } )
204+ } )
170205 . unwrap_or_else ( |_| OutputType :: stdout ( ) ) )
171206 }
172207
@@ -187,8 +222,8 @@ impl OutputType {
187222 pub fn handle < ' a > ( & ' a mut self ) -> Result < OutputHandle < ' a > > {
188223 Ok ( match * self {
189224 #[ cfg( feature = "paging" ) ]
190- OutputType :: Pager ( ref mut command ) => OutputHandle :: IoWrite (
191- command
225+ OutputType :: Pager ( ref mut proc ) => OutputHandle :: IoWrite (
226+ proc . child
192227 . stdin
193228 . as_mut ( )
194229 . ok_or ( "Could not open stdin for pager" ) ?,
@@ -204,8 +239,8 @@ impl OutputType {
204239impl Drop for OutputType {
205240 fn drop ( & mut self ) {
206241 match * self {
207- OutputType :: Pager ( ref mut command ) => {
208- let _ = command . wait ( ) ;
242+ OutputType :: Pager ( ref mut proc ) => {
243+ let _ = proc . child . wait ( ) ;
209244 }
210245 OutputType :: BuiltinPager ( ref mut pager) => {
211246 if pager. handle . is_some ( ) {
0 commit comments