[Sumover-dev] [svn commit] r4132 - rat/trunk

sumover-dev at cs.ucl.ac.uk sumover-dev at cs.ucl.ac.uk
Thu Apr 3 18:43:33 BST 2008


Author: piers
Date: Thu Apr  3 18:43:32 2008
New Revision: 4132

Modified:
   rat/trunk/main_control.c

Log:
Modified signal handling so that RAT doesn't exit if it is suspended by the shell (e.g. by hitting ctrl-Z - which sends a SIGTSTP followed by a SIGSTOP to the process). The existing SIGCHLD handler assumed that the the signal was generated as result of child process abnormal termination, however the SIGCHLD signal is also sent to the process parent when the child process resumes from a SIGSTOP. The sigchld_handler() been modified to catch the SIGCONT signal that is sent when the shell resumes the process (e.g.  types 'bg' or sends a SIGCONT) - in which case it will ignore the resulting two SIGCHLD signals generated by resumption of ratmedia and ratui.


Modified: rat/trunk/main_control.c
==============================================================================
--- rat/trunk/main_control.c	(original)
+++ rat/trunk/main_control.c	Thu Apr  3 18:43:32 2008
@@ -44,6 +44,7 @@
 pid_t       pid_ui, pid_engine;
 int         should_exit;
 int	    ui_enabled = TRUE;
+int	    continuing_from_stop=0;
 
 static int ttl = 127;
 
@@ -327,10 +328,19 @@
 sigchld_handler(int signal)
 {
         UNUSED(signal);
-        /* Child has terminated or stopped.  Try to shutdown nicely... */
         debug_msg("Caught signal SIGCHLD: %d\n", signal);
-        should_exit = TRUE;
-	wait(NULL);	/* Buffy, the zombie slayer... */
+	if (signal == SIGCONT)  {
+	  continuing_from_stop=2;
+          debug_msg("Ignoring signal SIGCONT as we've probably just come back from being suspended(SIGTSTP/SIGSTOP): %d\n", signal);
+	} else {
+	  if (--continuing_from_stop==-1) {
+          /* Child has terminated or stopped.  Try to shutdown nicely... */
+		should_exit = TRUE;
+          	wait(NULL);	/* Buffy, the zombie slayer... */
+		return;
+	  }
+	  debug_msg("Ignoring signal SIGCHLD as we've probably just come back from being suspended(SIGTSTP/SIGSTOP): %d\n", signal);
+	}
 }
 
 #else
@@ -469,6 +479,7 @@
 #ifdef WIN32
         win32_create_null_window(); /* Needed to listen to messages */
 #else
+        signal(SIGCONT, sigchld_handler);
         signal(SIGCHLD, sigchld_handler);
         signal(SIGINT, sigint_handler);
 	signal(SIGTERM, sigint_handler);



More information about the Sumover-dev mailing list