gnugo-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnugo-devel] sigterm signal handler


From: Gunnar Farneback
Subject: [gnugo-devel] sigterm signal handler
Date: Wed, 11 Sep 2002 19:31:38 +0200
User-agent: EMH/1.14.1 SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.3 Emacs/20.7 (sparc-sun-solaris2.7) (with unibyte mode)

This patch kills off the SIGTERM signal handler. Since we now store
complete sgf files at each move, there's no longer any reason to
resist dying in the default way from a SIGTERM.

As a consequence we no longer need the call to alarm() and can thus
skip the configure test for alarm. (There's no hurry running
autoconf. It can wait until the 3.3.9 release.)

- configure test for alarm removed
- sigterm_handler() and volatile variable time_to_die removed

/Gunnar

Index: configure.in
===================================================================
RCS file: /cvsroot/gnugo/gnugo/configure.in,v
retrieving revision 1.60
diff -u -r1.60 configure.in
--- configure.in        5 Sep 2002 16:13:53 -0000       1.60
+++ configure.in        11 Sep 2002 14:40:48 -0000
@@ -160,10 +160,9 @@
 AC_CHECK_SIZEOF(long)
 
 dnl results of setlinebuf test used in interface/play_ascii.c
-dnl alarm not available in VC
 dnl vsnprintf not universally available
 dnl usleep not available in Unicos and mingw32
-AC_CHECK_FUNCS(setlinebuf alarm vsnprintf gettimeofday usleep times)
+AC_CHECK_FUNCS(setlinebuf vsnprintf gettimeofday usleep times)
 
 dnl if snprintf not available try to use g_snprintf from glib
 if test $ac_cv_func_vsnprintf = no; then
Index: interface/main.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/main.c,v
retrieving revision 1.48
diff -u -r1.48 main.c
--- interface/main.c    10 Sep 2002 20:09:52 -0000      1.48
+++ interface/main.c    11 Sep 2002 14:40:55 -0000
@@ -44,8 +44,6 @@
 # endif
 #endif
 
-#include <signal.h>
-
 #include <liberty.h>
 
 #include "gg-getopt.h"
@@ -257,8 +255,6 @@
 
 float memory = (float) DEFAULT_MEMORY;   /* Megabytes used for hash table. */
 
-static void sigterm_handler(int);
-
 
 int
 main(int argc, char *argv[])
@@ -298,9 +294,6 @@
 
   komi = 0.0;
   
-  /* Set SIGTERM handler. */
-  signal(SIGTERM, sigterm_handler);
-
   level = DEFAULT_LEVEL;
   semeai_variations = DEFAULT_SEMEAI_VARIATIONS;
 
@@ -1191,40 +1184,6 @@
   return 0;
 }  /* end main */
 
-
-
-/* 
- * Cgoban sends us a sigterm when it wants us to die. But it doesn't
- * close the pipe, so we cannot rely on gmp to pick up an error.
- * 
- * We want to keep control so we can close the output sgf file
- * properly, so we trap the signal.
- */
-
-volatile int time_to_die = 0;   /* set by signal handlers */
-
-static void 
-sigterm_handler(int sig)
-{
-  time_to_die = 1;
-  if (!quiet)
-    write(2, "*SIGTERM*\n", 10);  /* bad to use stdio in a signal handler */
-
-  close(0);                  /* this forces gmp.c to return an gmp_err */
-
-  /* I thought signal handlers were one-shot, yet on my linux box it is kept.
-   * Restore the default behaviour so that a second signal has the
-   * original effect - in case we really are stuck in a loop.
-   */
-  signal(sig, SIG_DFL);
-
-  /* schedule a SIGALRM in 5 seconds, in case we haven't cleaned up by then
-   * - cgoban sends the SIGTERM only once 
-   */
-#ifdef HAVE_ALARM
-  alarm(5);
-#endif
-}
 
 
 static void
Index: interface/play_ascii.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/play_ascii.c,v
retrieving revision 1.25
diff -u -r1.25 play_ascii.c
--- interface/play_ascii.c      10 Sep 2002 20:06:02 -0000      1.25
+++ interface/play_ascii.c      11 Sep 2002 14:40:57 -0000
@@ -594,7 +594,7 @@
       computer_move(gameinfo, &passes);
     
     /* main ASCII Play loop */
-    while (passes < 2 && !time_to_die) {
+    while (passes < 2) {
       /* Display game board. */
       if (opt_showboard)
        ascii_showboard();
Index: interface/play_gmp.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/play_gmp.c,v
retrieving revision 1.11
diff -u -r1.11 play_gmp.c
--- interface/play_gmp.c        10 Sep 2002 20:06:02 -0000      1.11
+++ interface/play_gmp.c        11 Sep 2002 14:40:58 -0000
@@ -66,9 +66,7 @@
     gmp_startGame(ge, -1, -1, 5.5, 0, -1);     
   do {
     message = gmp_check(ge, 1, NULL, NULL, &error);
-  } while (!time_to_die
-          && (message == gmp_nothing
-              || message == gmp_reset));
+  } while (message == gmp_nothing || message == gmp_reset);
   
   if (message == gmp_err)  {
     fprintf(stderr, "gnugo-gmp: Error \"%s\" occurred.\n", error);
@@ -120,7 +118,7 @@
   sgfOverwritePropertyInt(sgftree.root, "HA", gameinfo->handicap);
 
   /* main GMP loop */
-  while (passes < 2 && !time_to_die) {
+  while (passes < 2) {
 
     if (to_move == yourcolor) {
       moveval = 0;
@@ -214,7 +212,7 @@
   sgfWriteResult(sgftree.root, score, 1);
   sgffile_output(&sgftree);
   
-  while (!time_to_die) {
+  while (1) {
     message = gmp_check(ge, 1, &j, &i, &error);
     if (!quiet)
       fprintf(stderr, "Message %d from gmp\n", message);
Index: interface/play_solo.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/play_solo.c,v
retrieving revision 1.17
diff -u -r1.17 play_solo.c
--- interface/play_solo.c       10 Sep 2002 20:06:02 -0000      1.17
+++ interface/play_solo.c       11 Sep 2002 14:40:58 -0000
@@ -79,7 +79,7 @@
   
   t1 = gg_cputime();
   memset(&totalstats, '\0', sizeof(totalstats));
-  while (passes < 2 && --moves >= 0 && !time_to_die) {
+  while (passes < 2 && --moves >= 0) {
     reset_owl_node_counter();
     move_val = gnugo_genmove(&i, &j, gameinfo->to_move);
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]