@@ -1576,13 +1576,13 @@ static void
15761576initsigs (void )
15771577{
15781578#ifdef SIGPIPE
1579- signal (SIGPIPE , SIG_IGN );
1579+ PyOS_setsig (SIGPIPE , SIG_IGN );
15801580#endif
15811581#ifdef SIGXFZ
1582- signal (SIGXFZ , SIG_IGN );
1582+ PyOS_setsig (SIGXFZ , SIG_IGN );
15831583#endif
15841584#ifdef SIGXFSZ
1585- signal (SIGXFSZ , SIG_IGN );
1585+ PyOS_setsig (SIGXFSZ , SIG_IGN );
15861586#endif
15871587 PyOS_InitInterrupts (); /* May imply initsignal() */
15881588}
@@ -1646,18 +1646,14 @@ PyOS_getsig(int sig)
16461646{
16471647#ifdef HAVE_SIGACTION
16481648 struct sigaction context ;
1649- /* Initialize context.sa_handler to SIG_ERR which makes about as
1650- * much sense as anything else. It should get overwritten if
1651- * sigaction actually succeeds and otherwise we avoid an
1652- * uninitialized memory read.
1653- */
1654- context .sa_handler = SIG_ERR ;
1655- sigaction (sig , NULL , & context );
1649+ if (sigaction (sig , NULL , & context ) == -1 )
1650+ return SIG_ERR ;
16561651 return context .sa_handler ;
16571652#else
16581653 PyOS_sighandler_t handler ;
16591654 handler = signal (sig , SIG_IGN );
1660- signal (sig , handler );
1655+ if (handler != SIG_ERR )
1656+ signal (sig , handler );
16611657 return handler ;
16621658#endif
16631659}
@@ -1666,20 +1662,19 @@ PyOS_sighandler_t
16661662PyOS_setsig (int sig , PyOS_sighandler_t handler )
16671663{
16681664#ifdef HAVE_SIGACTION
1669- struct sigaction context ;
1670- PyOS_sighandler_t oldhandler ;
1671- /* Initialize context.sa_handler to SIG_ERR which makes about as
1672- * much sense as anything else. It should get overwritten if
1673- * sigaction actually succeeds and otherwise we avoid an
1674- * uninitialized memory read.
1675- */
1676- context .sa_handler = SIG_ERR ;
1677- sigaction (sig , NULL , & context );
1678- oldhandler = context .sa_handler ;
1665+ struct sigaction context , ocontext ;
16791666 context .sa_handler = handler ;
1680- sigaction (sig , & context , NULL );
1681- return oldhandler ;
1667+ sigemptyset (& context .sa_mask );
1668+ context .sa_flags = 0 ;
1669+ if (sigaction (sig , & context , & ocontext ) == -1 )
1670+ return SIG_ERR ;
1671+ return ocontext .sa_handler ;
16821672#else
1683- return signal (sig , handler );
1673+ PyOS_sighandler_t oldhandler ;
1674+ oldhandler = signal (sig , handler );
1675+ #ifdef HAVE_SIGINTERRUPT
1676+ siginterrupt (sig , 1 );
1677+ #endif
1678+ return oldhandler ;
16841679#endif
16851680}
0 commit comments