From e4927433de9601f4e34126f740915ffa4e2ec663 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sun, 26 Jul 2015 10:34:41 +0100 Subject: win32: remove setitimer implementation and SIGALRM handling Commit 69f49ea imported a setitimer implementation from git. Since setitimer isn't used at all in BusyBox it can be removed. The same technique could be used to implement alarm but nothing in the WIN32 port uses that (yet). --- include/mingw.h | 10 +---- win32/mingw.c | 124 -------------------------------------------------------- 2 files changed, 1 insertion(+), 133 deletions(-) diff --git a/include/mingw.h b/include/mingw.h index 005c17d14..c15161483 100644 --- a/include/mingw.h +++ b/include/mingw.h @@ -123,13 +123,11 @@ struct sigaction { #define sigemptyset(x) (void)0 #define SA_RESTART 0 -int sigaction(int sig, struct sigaction *in, struct sigaction *out); -sighandler_t mingw_signal(int sig, sighandler_t handler); +NOIMPL(sigaction,int sig UNUSED_PARAM, struct sigaction *in UNUSED_PARAM, struct sigaction *out UNUSED_PARAM); NOIMPL(sigfillset,int *mask UNUSED_PARAM); NOIMPL(FAST_FUNC sigprocmask_allsigs, int how UNUSED_PARAM); NOIMPL(FAST_FUNC sigaction_set,int signo UNUSED_PARAM, const struct sigaction *sa UNUSED_PARAM); -#define signal mingw_signal /* * stdio.h */ @@ -342,12 +340,6 @@ struct timespec { long int tv_nsec; }; #endif -struct itimerval { - struct timeval it_value, it_interval; -}; -#define ITIMER_REAL 0 - -int setitimer(int type, struct itimerval *in, struct itimerval *out); /* * sys/wait.h diff --git a/win32/mingw.c b/win32/mingw.c index 6b63e2487..14cfdd992 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -707,130 +707,6 @@ clock_t times(struct tms *buf) return 0; } -static HANDLE timer_event; -static HANDLE timer_thread; -static int timer_interval; -static int one_shot; -static sighandler_t timer_fn = SIG_DFL; - -/* The timer works like this: - * The thread, ticktack(), is a trivial routine that most of the time - * only waits to receive the signal to terminate. The main thread tells - * the thread to terminate by setting the timer_event to the signalled - * state. - * But ticktack() interrupts the wait state after the timer's interval - * length to call the signal handler. - */ - -static __stdcall unsigned ticktack(void *dummy UNUSED_PARAM) -{ - while (WaitForSingleObject(timer_event, timer_interval) == WAIT_TIMEOUT) { - if (timer_fn == SIG_DFL) - bb_error_msg_and_die("Alarm"); - if (timer_fn != SIG_IGN) - timer_fn(SIGALRM); - if (one_shot) - break; - } - return 0; -} - -static int start_timer_thread(void) -{ - timer_event = CreateEvent(NULL, FALSE, FALSE, NULL); - if (timer_event) { - timer_thread = (HANDLE) _beginthreadex(NULL, 0, ticktack, NULL, 0, NULL); - if (!timer_thread ) { - errno = ENOMEM; - return -1; - } - } else { - errno = ENOMEM; - return -1; - } - return 0; -} - -static void stop_timer_thread(void) -{ - if (timer_event) - SetEvent(timer_event); /* tell thread to terminate */ - if (timer_thread) { - int rc = WaitForSingleObject(timer_thread, 1000); - if (rc == WAIT_TIMEOUT) - fprintf(stderr, "timer thread did not terminate timely"); - else if (rc != WAIT_OBJECT_0) - fprintf(stderr, "waiting for timer thread failed: %lu", - GetLastError()); - CloseHandle(timer_thread); - } - if (timer_event) - CloseHandle(timer_event); - timer_event = NULL; - timer_thread = NULL; -} - -static inline int is_timeval_eq(const struct timeval *i1, const struct timeval *i2) -{ - return i1->tv_sec == i2->tv_sec && i1->tv_usec == i2->tv_usec; -} - -int setitimer(int type UNUSED_PARAM, struct itimerval *in, struct itimerval *out) -{ - static const struct timeval zero; - static int atexit_done; - - if (out != NULL) { - errno = EINVAL; - return -1; - } - if (!is_timeval_eq(&in->it_interval, &zero) && - !is_timeval_eq(&in->it_interval, &in->it_value)) { - errno = EINVAL; - return -1; - } - - if (timer_thread) - stop_timer_thread(); - - if (is_timeval_eq(&in->it_value, &zero) && - is_timeval_eq(&in->it_interval, &zero)) - return 0; - - timer_interval = in->it_value.tv_sec * 1000 + in->it_value.tv_usec / 1000; - one_shot = is_timeval_eq(&in->it_interval, &zero); - if (!atexit_done) { - atexit(stop_timer_thread); - atexit_done = 1; - } - return start_timer_thread(); -} - -int sigaction(int sig, struct sigaction *in, struct sigaction *out) -{ - if (sig != SIGALRM) { - errno = EINVAL; - return -1; - } - if (out != NULL) { - errno = EINVAL; - return -1; - } - - timer_fn = in->sa_handler; - return 0; -} - -#undef signal -sighandler_t mingw_signal(int sig, sighandler_t handler) -{ - sighandler_t old = timer_fn; - if (sig != SIGALRM) - return signal(sig, handler); - timer_fn = handler; - return old; -} - int link(const char *oldpath, const char *newpath) { typedef BOOL (WINAPI *T)(const char*, const char*, LPSECURITY_ATTRIBUTES); -- cgit v1.2.3-55-g6feb