44
44
static bool stdin_received = false ;
45
45
static bool stdin_sigint = false ;
46
46
// Global variable to store the original SIGINT handler
47
- static struct sigaction originalSigintAction = { 0 } ;
47
+ static PyOS_sighandler_t originalSigintAction = NULL ;
48
48
49
49
// Signal handler for SIGINT, only sets a flag to exit the run loop
50
50
static void handleSigint (int signal) {
@@ -57,10 +57,7 @@ static int wait_for_stdin() {
57
57
stdin_sigint = false ;
58
58
59
59
// Set up a SIGINT handler to interrupt the event loop if ctrl+c comes in too
60
- struct sigaction customAction = {0 };
61
- customAction.sa_handler = handleSigint;
62
- // Set the new handler and store the old one
63
- sigaction (SIGINT, &customAction, &originalSigintAction);
60
+ originalSigintAction = PyOS_setsig (SIGINT, handleSigint);
64
61
65
62
// Create an NSFileHandle for standard input
66
63
NSFileHandle *stdinHandle = [NSFileHandle fileHandleWithStandardInput ];
@@ -93,7 +90,7 @@ static int wait_for_stdin() {
93
90
[[NSNotificationCenter defaultCenter ] removeObserver: stdinHandle];
94
91
95
92
// Restore the original SIGINT handler upon exiting the function
96
- sigaction (SIGINT, & originalSigintAction, NULL );
93
+ PyOS_setsig (SIGINT, originalSigintAction);
97
94
return 1 ;
98
95
}
99
96
}
0 commit comments