diff options
author | Ron Yorston <rmy@pobox.com> | 2015-07-26 10:34:41 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2015-07-26 10:34:41 +0100 |
commit | e4927433de9601f4e34126f740915ffa4e2ec663 (patch) | |
tree | a01d36a18fd161305d1bac9e46044bd89da3f886 | |
parent | 843b490b155eb2e531359910b1d4861f83d69109 (diff) | |
download | busybox-w32-e4927433de9601f4e34126f740915ffa4e2ec663.tar.gz busybox-w32-e4927433de9601f4e34126f740915ffa4e2ec663.tar.bz2 busybox-w32-e4927433de9601f4e34126f740915ffa4e2ec663.zip |
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).
-rw-r--r-- | include/mingw.h | 10 | ||||
-rw-r--r-- | win32/mingw.c | 124 |
2 files changed, 1 insertions, 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 { | |||
123 | #define sigemptyset(x) (void)0 | 123 | #define sigemptyset(x) (void)0 |
124 | #define SA_RESTART 0 | 124 | #define SA_RESTART 0 |
125 | 125 | ||
126 | int sigaction(int sig, struct sigaction *in, struct sigaction *out); | 126 | NOIMPL(sigaction,int sig UNUSED_PARAM, struct sigaction *in UNUSED_PARAM, struct sigaction *out UNUSED_PARAM); |
127 | sighandler_t mingw_signal(int sig, sighandler_t handler); | ||
128 | NOIMPL(sigfillset,int *mask UNUSED_PARAM); | 127 | NOIMPL(sigfillset,int *mask UNUSED_PARAM); |
129 | NOIMPL(FAST_FUNC sigprocmask_allsigs, int how UNUSED_PARAM); | 128 | NOIMPL(FAST_FUNC sigprocmask_allsigs, int how UNUSED_PARAM); |
130 | NOIMPL(FAST_FUNC sigaction_set,int signo UNUSED_PARAM, const struct sigaction *sa UNUSED_PARAM); | 129 | NOIMPL(FAST_FUNC sigaction_set,int signo UNUSED_PARAM, const struct sigaction *sa UNUSED_PARAM); |
131 | 130 | ||
132 | #define signal mingw_signal | ||
133 | /* | 131 | /* |
134 | * stdio.h | 132 | * stdio.h |
135 | */ | 133 | */ |
@@ -342,12 +340,6 @@ struct timespec { | |||
342 | long int tv_nsec; | 340 | long int tv_nsec; |
343 | }; | 341 | }; |
344 | #endif | 342 | #endif |
345 | struct itimerval { | ||
346 | struct timeval it_value, it_interval; | ||
347 | }; | ||
348 | #define ITIMER_REAL 0 | ||
349 | |||
350 | int setitimer(int type, struct itimerval *in, struct itimerval *out); | ||
351 | 343 | ||
352 | /* | 344 | /* |
353 | * sys/wait.h | 345 | * 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) | |||
707 | return 0; | 707 | return 0; |
708 | } | 708 | } |
709 | 709 | ||
710 | static HANDLE timer_event; | ||
711 | static HANDLE timer_thread; | ||
712 | static int timer_interval; | ||
713 | static int one_shot; | ||
714 | static sighandler_t timer_fn = SIG_DFL; | ||
715 | |||
716 | /* The timer works like this: | ||
717 | * The thread, ticktack(), is a trivial routine that most of the time | ||
718 | * only waits to receive the signal to terminate. The main thread tells | ||
719 | * the thread to terminate by setting the timer_event to the signalled | ||
720 | * state. | ||
721 | * But ticktack() interrupts the wait state after the timer's interval | ||
722 | * length to call the signal handler. | ||
723 | */ | ||
724 | |||
725 | static __stdcall unsigned ticktack(void *dummy UNUSED_PARAM) | ||
726 | { | ||
727 | while (WaitForSingleObject(timer_event, timer_interval) == WAIT_TIMEOUT) { | ||
728 | if (timer_fn == SIG_DFL) | ||
729 | bb_error_msg_and_die("Alarm"); | ||
730 | if (timer_fn != SIG_IGN) | ||
731 | timer_fn(SIGALRM); | ||
732 | if (one_shot) | ||
733 | break; | ||
734 | } | ||
735 | return 0; | ||
736 | } | ||
737 | |||
738 | static int start_timer_thread(void) | ||
739 | { | ||
740 | timer_event = CreateEvent(NULL, FALSE, FALSE, NULL); | ||
741 | if (timer_event) { | ||
742 | timer_thread = (HANDLE) _beginthreadex(NULL, 0, ticktack, NULL, 0, NULL); | ||
743 | if (!timer_thread ) { | ||
744 | errno = ENOMEM; | ||
745 | return -1; | ||
746 | } | ||
747 | } else { | ||
748 | errno = ENOMEM; | ||
749 | return -1; | ||
750 | } | ||
751 | return 0; | ||
752 | } | ||
753 | |||
754 | static void stop_timer_thread(void) | ||
755 | { | ||
756 | if (timer_event) | ||
757 | SetEvent(timer_event); /* tell thread to terminate */ | ||
758 | if (timer_thread) { | ||
759 | int rc = WaitForSingleObject(timer_thread, 1000); | ||
760 | if (rc == WAIT_TIMEOUT) | ||
761 | fprintf(stderr, "timer thread did not terminate timely"); | ||
762 | else if (rc != WAIT_OBJECT_0) | ||
763 | fprintf(stderr, "waiting for timer thread failed: %lu", | ||
764 | GetLastError()); | ||
765 | CloseHandle(timer_thread); | ||
766 | } | ||
767 | if (timer_event) | ||
768 | CloseHandle(timer_event); | ||
769 | timer_event = NULL; | ||
770 | timer_thread = NULL; | ||
771 | } | ||
772 | |||
773 | static inline int is_timeval_eq(const struct timeval *i1, const struct timeval *i2) | ||
774 | { | ||
775 | return i1->tv_sec == i2->tv_sec && i1->tv_usec == i2->tv_usec; | ||
776 | } | ||
777 | |||
778 | int setitimer(int type UNUSED_PARAM, struct itimerval *in, struct itimerval *out) | ||
779 | { | ||
780 | static const struct timeval zero; | ||
781 | static int atexit_done; | ||
782 | |||
783 | if (out != NULL) { | ||
784 | errno = EINVAL; | ||
785 | return -1; | ||
786 | } | ||
787 | if (!is_timeval_eq(&in->it_interval, &zero) && | ||
788 | !is_timeval_eq(&in->it_interval, &in->it_value)) { | ||
789 | errno = EINVAL; | ||
790 | return -1; | ||
791 | } | ||
792 | |||
793 | if (timer_thread) | ||
794 | stop_timer_thread(); | ||
795 | |||
796 | if (is_timeval_eq(&in->it_value, &zero) && | ||
797 | is_timeval_eq(&in->it_interval, &zero)) | ||
798 | return 0; | ||
799 | |||
800 | timer_interval = in->it_value.tv_sec * 1000 + in->it_value.tv_usec / 1000; | ||
801 | one_shot = is_timeval_eq(&in->it_interval, &zero); | ||
802 | if (!atexit_done) { | ||
803 | atexit(stop_timer_thread); | ||
804 | atexit_done = 1; | ||
805 | } | ||
806 | return start_timer_thread(); | ||
807 | } | ||
808 | |||
809 | int sigaction(int sig, struct sigaction *in, struct sigaction *out) | ||
810 | { | ||
811 | if (sig != SIGALRM) { | ||
812 | errno = EINVAL; | ||
813 | return -1; | ||
814 | } | ||
815 | if (out != NULL) { | ||
816 | errno = EINVAL; | ||
817 | return -1; | ||
818 | } | ||
819 | |||
820 | timer_fn = in->sa_handler; | ||
821 | return 0; | ||
822 | } | ||
823 | |||
824 | #undef signal | ||
825 | sighandler_t mingw_signal(int sig, sighandler_t handler) | ||
826 | { | ||
827 | sighandler_t old = timer_fn; | ||
828 | if (sig != SIGALRM) | ||
829 | return signal(sig, handler); | ||
830 | timer_fn = handler; | ||
831 | return old; | ||
832 | } | ||
833 | |||
834 | int link(const char *oldpath, const char *newpath) | 710 | int link(const char *oldpath, const char *newpath) |
835 | { | 711 | { |
836 | typedef BOOL (WINAPI *T)(const char*, const char*, LPSECURITY_ATTRIBUTES); | 712 | typedef BOOL (WINAPI *T)(const char*, const char*, LPSECURITY_ATTRIBUTES); |