[Pommed-commits] r396 - in trunk: client-common gpomme wmpomme

jblache at alioth.debian.org jblache at alioth.debian.org
Tue Nov 27 20:11:13 UTC 2007


Author: jblache
Date: 2007-11-27 20:11:12 +0000 (Tue, 27 Nov 2007)
New Revision: 396

Modified:
   trunk/client-common/video-client.c
   trunk/gpomme/gpomme.c
   trunk/wmpomme/wmpomme.c
Log:
Use a SIGCHLD handler instead of waiting for the child to exit.

Allows running e.g. grandr or urandr on video switch key press without blocking the frontend.


Modified: trunk/client-common/video-client.c
===================================================================
--- trunk/client-common/video-client.c	2007-11-27 16:43:47 UTC (rev 395)
+++ trunk/client-common/video-client.c	2007-11-27 20:11:12 UTC (rev 396)
@@ -26,7 +26,6 @@
 #include <pwd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/wait.h>
 
 #include <errno.h>
 
@@ -35,6 +34,9 @@
 
 static char *vsw_user = NULL;
 
+/*
+ * NOTE: you MUST install a SIGCHLD handler if you use this function
+ */
 void
 mbp_video_switch(void)
 {
@@ -92,14 +94,5 @@
       fprintf(stderr, "Could not fork: %s\n", strerror(errno));
       return;
     }
-  else
-    {
-      waitpid(ret, &ret, 0);
-      if ((WIFEXITED(ret) == 0) || (WEXITSTATUS(ret) != 0))
-        {
-          fprintf(stderr, "Video switch script failed");
-          return;
-        }
-    }
 }
 

Modified: trunk/gpomme/gpomme.c
===================================================================
--- trunk/gpomme/gpomme.c	2007-11-27 16:43:47 UTC (rev 395)
+++ trunk/gpomme/gpomme.c	2007-11-27 20:11:12 UTC (rev 396)
@@ -30,6 +30,9 @@
 #include <unistd.h>
 #include <signal.h>
 
+#include <sys/types.h>
+#include <sys/wait.h>
+
 #ifndef NO_SYS_INOTIFY_H
 # include <sys/inotify.h>
 #else
@@ -470,6 +473,18 @@
   gtk_main_quit();
 }
 
+void
+sig_chld_handler(int signo)
+{
+  int ret;
+
+  do
+    {
+      ret = waitpid(-1, NULL, WNOHANG);
+    }
+  while (ret > 0);
+}
+
 int main(int argc, char **argv)
 {
   int c;
@@ -519,6 +534,7 @@
 
   signal(SIGINT, sig_int_term_handler);
   signal(SIGTERM, sig_int_term_handler);
+  signal(SIGCHLD, sig_chld_handler);
 
   create_window();
 

Modified: trunk/wmpomme/wmpomme.c
===================================================================
--- trunk/wmpomme/wmpomme.c	2007-11-27 16:43:47 UTC (rev 395)
+++ trunk/wmpomme/wmpomme.c	2007-11-27 20:11:12 UTC (rev 396)
@@ -33,6 +33,9 @@
 #include <unistd.h>
 #include <ctype.h>
 
+#include <sys/types.h>
+#include <sys/wait.h>
+
 #include <signal.h>
 
 #include <X11/xpm.h>
@@ -541,6 +544,18 @@
   running = 0;
 }
 
+void
+sig_chld_handler(int signo)
+{
+  int ret;
+
+  do
+    {
+      ret = waitpid(-1, NULL, WNOHANG);
+    }
+  while (ret > 0);
+}
+
 int
 main(int argc, char **argv)
 {
@@ -548,6 +563,7 @@
 
   signal(SIGINT, sig_int_term_handler);
   signal(SIGTERM, sig_int_term_handler);
+  signal(SIGCHLD, sig_chld_handler);
 
   ProgName = argv[0];
   if (strlen(ProgName) >= 5)




More information about the Pommed-commits mailing list