X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=idle.c;h=4ea21a3c4b4bfc74d712166b4fa900a2b4e3bf9c;hb=da989f7b8294e342572ec5f27f1a6f3f2b1fe56f;hp=8e6f36dc9c2cb54dc08c1fb2e4ca590c8cce99aa;hpb=f6086d6ab4c1f76d9b640c4e44c340f01515e40b;p=~andy%2Ffetchmail diff --git a/idle.c b/idle.c index 8e6f36dc..4ea21a3c 100644 --- a/idle.c +++ b/idle.c @@ -21,7 +21,7 @@ MIT license. Compile with -DMAIN to build the demonstrator. #include #include #include -#include +#include /* for ROOT_UID */ #ifndef TRUE #define TRUE 1 @@ -42,9 +42,9 @@ volatile int lastsig; /* last signal received */ */ static sig_atomic_t alarm_latch = FALSE; -void gotsigalrm(int sig) +RETSIGTYPE gotsigalrm(int sig) { - signal(sig, gotsigalrm); + set_signal_handler(sig, gotsigalrm); lastsig = sig; alarm_latch = TRUE; } @@ -108,9 +108,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 */ @@ -121,7 +120,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 /* @@ -147,20 +146,21 @@ int interruptible_idle(int seconds) #endif #else /* EMX */ alarm_latch = FALSE; - signal(SIGALRM, gotsigalrm); + set_signal_handler(SIGALRM, gotsigalrm); _beginthread(itimerthread, NULL, 32768, NULL); /* see similar code above */ if (!alarm_latch) pause(); - signal(SIGALRM, SIG_IGN); + set_signal_handler(SIGALRM, SIG_IGN); #endif /* ! EMX */ - if (lastsig == SIGUSR1 || ((seconds && !getuid()) && lastsig == SIGHUP)) + if (lastsig == SIGUSR1 || ((seconds && getuid() == ROOT_UID) + && lastsig == SIGHUP)) awoken = TRUE; /* now lock out interrupts again */ - signal(SIGUSR1, SIG_IGN); - if (!getuid()) - signal(SIGHUP, SIG_IGN); + set_signal_handler(SIGUSR1, SIG_IGN); + if (getuid() == ROOT_UID) + set_signal_handler(SIGHUP, SIG_IGN); return(awoken ? lastsig : 0); }