changeset 13391:b6c3752d9544

handle sigchld in mplayer.c
author faust3
date Sun, 19 Sep 2004 18:45:11 +0000
parents 1f415687a3f7
children e4b8827f0018
files libmenu/menu_console.c mplayer.c
diffstat 2 files changed, 21 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/libmenu/menu_console.c	Sun Sep 19 18:36:18 2004 +0000
+++ b/libmenu/menu_console.c	Sun Sep 19 18:45:11 2004 +0000
@@ -245,15 +245,16 @@
   r = select(max_fd+1,&rfd, NULL, NULL, &tv);
   if(r == 0) {
     r = waitpid(mpriv->child,&child_status,WNOHANG);
-    if(r > 0) {
-      printf("child died\n");
-    for(i = 0 ; i < 3 ; i++) 
-      close(mpriv->child_fd[i]);
-    mpriv->child = 0;
-    mpriv->prompt = mpriv->mp_prompt;
-    //add_line(mpriv,"Child process exited");
-    } else if(r < 0)
-      printf("waitpid error: %s\n",strerror(errno));
+    if(r < 0){
+      if(errno==ECHILD){  ///exiting childs get handled in mplayer.c
+        for(i = 0 ; i < 3 ; i++) 
+          close(mpriv->child_fd[i]);
+        mpriv->child = 0;
+        mpriv->prompt = mpriv->mp_prompt;
+        //add_line(mpriv,"Child process exited");    
+      }
+      else printf("waitpid error: %s\n",strerror(errno));
+    }
   } else if(r < 0) {
     printf("select error\n");
     return;
--- a/mplayer.c	Sun Sep 19 18:36:18 2004 +0000
+++ b/mplayer.c	Sun Sep 19 18:45:11 2004 +0000
@@ -489,6 +489,13 @@
   exit_player_with_rc(how, 1);
 }
 
+#ifndef __MINGW32__
+static void child_sighandler(int x){  
+  pid_t pid;
+  while((pid=waitpid(-1,NULL,WNOHANG)) > 0);
+}
+#endif
+
 static void exit_sighandler(int x){
   static int sig_count=0;
   ++sig_count;
@@ -1148,7 +1155,10 @@
  }
 #endif
   
-
+  /// Catch signals
+#ifndef __MINGW32__
+  signal(SIGCHLD,child_sighandler);
+#endif
 
   //========= Catch terminate signals: ================
   // terminate requests: