X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=idle.c;h=04c191847870798f96634cf793f273724ce3c701;hb=24ab4a608c8ee1613698a1a312a7b30d138a241e;hp=155f434b02b0d8579282d99303cafa6f2bb72bcd;hpb=c8928081a5a9cbfaf16b14d4db57476bda8e1189;p=~andy%2Ffetchmail diff --git a/idle.c b/idle.c index 155f434b..04c19184 100644 --- a/idle.c +++ b/idle.c @@ -21,7 +21,6 @@ MIT license. Compile with -DMAIN to build the demonstrator. #include #include #include -#include #include /* for ROOT_UID */ #ifndef TRUE @@ -45,35 +44,17 @@ static sig_atomic_t alarm_latch = FALSE; void gotsigalrm(int sig) { - signal(sig, gotsigalrm); + set_signal_handler(sig, gotsigalrm); lastsig = sig; alarm_latch = TRUE; } #endif /* SLEEP_WITH_ALARM */ -#ifdef __EMX__ -/* Various EMX-specific definitions */ -static int itimerflag; - -void itimerthread(void* dummy) -{ - if (outlevel >= O_VERBOSE) - report(stderr, - GT_("fetchmail: thread sleeping for %d sec.\n"), poll_interval); - while(1) - { - _sleep2(poll_interval*1000); - kill((getpid()), SIGALRM); - } -} -#endif - int interruptible_idle(int seconds) /* time for a pause in the action; return TRUE if awakened by signal */ { int awoken = FALSE; -#ifndef __EMX__ #ifdef SLEEP_WITH_ALARM /* not normally on */ /* * We can't use sleep(3) here because we need an alarm(3) @@ -109,9 +90,8 @@ int interruptible_idle(int seconds) ntimeout.it_value.tv_sec = seconds; ntimeout.it_value.tv_usec = 0; - siginterrupt(SIGALRM, 1); alarm_latch = FALSE; - signal(SIGALRM, gotsigalrm); /* first trap signals */ + set_signal_handler(SIGALRM, gotsigalrm); /* first trap signals */ setitimer(ITIMER_REAL,&ntimeout,NULL); /* then start timer */ /* there is a very small window between the next two lines */ /* which could result in a deadlock. But this will now be */ @@ -122,7 +102,7 @@ int interruptible_idle(int seconds) ntimeout.it_interval.tv_sec = ntimeout.it_interval.tv_usec = 0; ntimeout.it_value.tv_sec = ntimeout.it_value.tv_usec = 0; setitimer(ITIMER_REAL,&ntimeout,NULL); /* now stop timer */ - signal(SIGALRM, SIG_IGN); + set_signal_handler(SIGALRM, SIG_IGN); } #else /* @@ -146,23 +126,14 @@ int interruptible_idle(int seconds) } while (lastsig == SIGCHLD); } #endif -#else /* EMX */ - alarm_latch = FALSE; - signal(SIGALRM, gotsigalrm); - _beginthread(itimerthread, NULL, 32768, NULL); - /* see similar code above */ - if (!alarm_latch) - pause(); - signal(SIGALRM, SIG_IGN); -#endif /* ! EMX */ if (lastsig == SIGUSR1 || ((seconds && getuid() == ROOT_UID) && lastsig == SIGHUP)) awoken = TRUE; /* now lock out interrupts again */ - signal(SIGUSR1, SIG_IGN); + set_signal_handler(SIGUSR1, SIG_IGN); if (getuid() == ROOT_UID) - signal(SIGHUP, SIG_IGN); + set_signal_handler(SIGHUP, SIG_IGN); return(awoken ? lastsig : 0); }