static void main_loop()
{
+ sigset_t newmask, oldmask, pendmask;
+
+ sigemptyset(&newmask);
+ sigaddset(&newmask,SIGINT);
+ sigaddset(&newmask,SIGTERM);
+ sigaddset(&newmask,SIGUSR1);
+
#ifdef X11
Region region = XCreateRegion();
#endif /* X11 */
info.looped = 0;
while (total_run_times == 0 || info.looped < total_run_times - 1) {
info.looped++;
+
+ /* block signals. we will inspect for pending signals later */
+ if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
+ CRIT_ERR("unable to sigprocmask()");
+
#ifdef X11
XFlush(display);
}
#endif /* X11 */
- /* inspect pending signal prior to entering next loop */
+ /* fetch pending signals prior to entering next loop */
+ if (sigpending(&pendmask) < 0)
+ CRIT_ERR("unable to sigpending()");
+
+ /* unblock signals of interest and let handler fly */
+ if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
+ CRIT_ERR("unable to sigprocmask()");
+
switch(g_signal_pending) {
case SIGUSR1:
{
int main(int argc, char **argv)
{
+ struct sigaction act, oact;
+
g_signal_pending=0;
memset(&info, 0, sizeof(info) );
}
/* Set signal handlers */
- if ( signal(SIGINT,signal_handler) == SIG_ERR ||
- signal(SIGUSR1,signal_handler) == SIG_ERR ||
- signal(SIGTERM,signal_handler) == SIG_ERR )
+ act.sa_handler = signal_handler;
+ sigemptyset(&act.sa_mask);
+ act.sa_flags = 0;
+ act.sa_flags |= SA_RESTART;
+
+ if ( sigaction(SIGINT,&act,&oact) < 0 ||
+ sigaction(SIGUSR1,&act,&oact) < 0 ||
+ sigaction(SIGTERM,&act,&oact) < 0 )
{
ERR("error setting signal handler: %s", strerror(errno) );
}