synchronous signal processing. fixes gentoo bug# 113219
authorPhilip Kovacs <pkovacs@users.sourceforge.net>
Wed, 23 Nov 2005 19:05:23 +0000 (19:05 +0000)
committerPhilip Kovacs <pkovacs@users.sourceforge.net>
Wed, 23 Nov 2005 19:05:23 +0000 (19:05 +0000)
git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky@426 7f574dfc-610e-0410-a909-a81674777703

ChangeLog
src/conky.c

index c17160a..aaf5c39 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 # $Id$
 
+2005-11-23
+       * Synchronous signal processing.  Fixes gentoo bug# 113219
+
 2005-11-22
        * Fixed IP address bug (sf.net bug 1359055)
 
index 9f4ce94..fb01cc9 100644 (file)
@@ -4060,6 +4060,13 @@ static void update_text()
 
 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 */
@@ -4067,6 +4074,11 @@ static void main_loop()
        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);
 
@@ -4287,7 +4299,14 @@ static void main_loop()
                }
 #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:
                        {
@@ -4964,6 +4983,8 @@ static const char *getopt_string = "vVdt:f:u:i:hc:w:x:y:a:"
 
 int main(int argc, char **argv)
 {
+       struct sigaction act, oact;
+
        g_signal_pending=0;
        memset(&info, 0, sizeof(info) );
 
@@ -5241,9 +5262,14 @@ int main(int argc, char **argv)
        }
 
        /* 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) );
        }