@@ -2420,110 +2420,15 @@ struct passwd *getpwuid(int uid UNUSED)
24202420 return p ;
24212421}
24222422
2423- static HANDLE timer_event ;
2424- static HANDLE timer_thread ;
2425- static int timer_interval ;
2426- static int one_shot ;
2427- static sig_handler_t timer_fn = SIG_DFL , sigint_fn = SIG_DFL ;
2428-
2429- /* The timer works like this:
2430- * The thread, ticktack(), is a trivial routine that most of the time
2431- * only waits to receive the signal to terminate. The main thread tells
2432- * the thread to terminate by setting the timer_event to the signalled
2433- * state.
2434- * But ticktack() interrupts the wait state after the timer's interval
2435- * length to call the signal handler.
2436- */
2437-
2438- static unsigned __stdcall ticktack (void * dummy UNUSED )
2439- {
2440- while (WaitForSingleObject (timer_event , timer_interval ) == WAIT_TIMEOUT ) {
2441- mingw_raise (SIGALRM );
2442- if (one_shot )
2443- break ;
2444- }
2445- return 0 ;
2446- }
2447-
2448- static int start_timer_thread (void )
2449- {
2450- timer_event = CreateEvent (NULL , FALSE, FALSE, NULL );
2451- if (timer_event ) {
2452- timer_thread = (HANDLE ) _beginthreadex (NULL , 0 , ticktack , NULL , 0 , NULL );
2453- if (!timer_thread )
2454- return errno = ENOMEM ,
2455- error ("cannot start timer thread" );
2456- } else
2457- return errno = ENOMEM ,
2458- error ("cannot allocate resources for timer" );
2459- return 0 ;
2460- }
2461-
2462- static void stop_timer_thread (void )
2463- {
2464- if (timer_event )
2465- SetEvent (timer_event ); /* tell thread to terminate */
2466- if (timer_thread ) {
2467- int rc = WaitForSingleObject (timer_thread , 10000 );
2468- if (rc == WAIT_TIMEOUT )
2469- error ("timer thread did not terminate timely" );
2470- else if (rc != WAIT_OBJECT_0 )
2471- error ("waiting for timer thread failed: %lu" ,
2472- GetLastError ());
2473- CloseHandle (timer_thread );
2474- }
2475- if (timer_event )
2476- CloseHandle (timer_event );
2477- timer_event = NULL ;
2478- timer_thread = NULL ;
2479- }
2480-
2481- static inline int is_timeval_eq (const struct timeval * i1 , const struct timeval * i2 )
2482- {
2483- return i1 -> tv_sec == i2 -> tv_sec && i1 -> tv_usec == i2 -> tv_usec ;
2484- }
2423+ static sig_handler_t sigint_fn = SIG_DFL ;
24852424
2486- int setitimer (int type UNUSED , struct itimerval * in , struct itimerval * out )
2487- {
2488- static const struct timeval zero ;
2489- static int atexit_done ;
2490-
2491- if (out )
2492- return errno = EINVAL ,
2493- error ("setitimer param 3 != NULL not implemented" );
2494- if (!is_timeval_eq (& in -> it_interval , & zero ) &&
2495- !is_timeval_eq (& in -> it_interval , & in -> it_value ))
2496- return errno = EINVAL ,
2497- error ("setitimer: it_interval must be zero or eq it_value" );
2498-
2499- if (timer_thread )
2500- stop_timer_thread ();
2501-
2502- if (is_timeval_eq (& in -> it_value , & zero ) &&
2503- is_timeval_eq (& in -> it_interval , & zero ))
2504- return 0 ;
2505-
2506- timer_interval = in -> it_value .tv_sec * 1000 + in -> it_value .tv_usec / 1000 ;
2507- one_shot = is_timeval_eq (& in -> it_interval , & zero );
2508- if (!atexit_done ) {
2509- atexit (stop_timer_thread );
2510- atexit_done = 1 ;
2511- }
2512- return start_timer_thread ();
2513- }
2514-
2515- int sigaction (int sig , struct sigaction * in , struct sigaction * out )
2425+ int sigaction (int sig , struct sigaction * in UNUSED , struct sigaction * out )
25162426{
25172427 if (sig == SIGCHLD )
25182428 return -1 ;
2519- else if (sig != SIGALRM )
2520- return errno = EINVAL ,
2521- error ("sigaction only implemented for SIGALRM" );
25222429 if (out )
25232430 return errno = EINVAL ,
25242431 error ("sigaction: param 3 != NULL not implemented" );
2525-
2526- timer_fn = in -> sa_handler ;
25272432 return 0 ;
25282433}
25292434
@@ -2533,11 +2438,6 @@ sig_handler_t mingw_signal(int sig, sig_handler_t handler)
25332438 sig_handler_t old ;
25342439
25352440 switch (sig ) {
2536- case SIGALRM :
2537- old = timer_fn ;
2538- timer_fn = handler ;
2539- break ;
2540-
25412441 case SIGINT :
25422442 old = sigint_fn ;
25432443 sigint_fn = handler ;
@@ -2554,15 +2454,6 @@ sig_handler_t mingw_signal(int sig, sig_handler_t handler)
25542454int mingw_raise (int sig )
25552455{
25562456 switch (sig ) {
2557- case SIGALRM :
2558- if (timer_fn == SIG_DFL ) {
2559- if (isatty (STDERR_FILENO ))
2560- fputs ("Alarm clock\n" , stderr );
2561- exit (128 + SIGALRM );
2562- } else if (timer_fn != SIG_IGN )
2563- timer_fn (SIGALRM );
2564- return 0 ;
2565-
25662457 case SIGINT :
25672458 if (sigint_fn == SIG_DFL )
25682459 exit (128 + SIGINT );
0 commit comments