Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2004:
[Freeciv-Dev] (PR#9032) Bug: odd "select" error message
Home

[Freeciv-Dev] (PR#9032) Bug: odd "select" error message

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#9032) Bug: odd "select" error message
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 17 Nov 2004 10:29:35 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=9032 >

> [jdorje - Thu Jun 24 13:39:37 2004]:
> 
> > [jdorje - Sat Jun 19 20:37:22 2004]:
> > 
> > When I run autogames I get this message
> > 
> > 1: select failed: Interrupted system call
> > 
> > periodically.  This is a recent development.
> 
> It's part of a bug in select.
> 
> If an error happens, it is logged but execution continues.
> 
> First of all, we shouldn't log an EINTR error.  This can happen any time
> and isn't necessarily an error.  In fact none of the other select calls
> report errors, so maybe we shouldn't log it at all.  Another problem is
> EINTR may not be portable; I don't know.
> 
> The bug is that if there is an error we can't rely on the values in the
> sets (according to "man select").  So we need to return immediately.

Or in some cases, run the loop again.

This is a more complete patch to fix the problem.

jason

Index: client/clinet.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/clinet.c,v
retrieving revision 1.107
diff -u -r1.107 clinet.c
--- client/clinet.c     14 Nov 2004 23:09:59 -0000      1.107
+++ client/clinet.c     17 Nov 2004 18:27:37 -0000
@@ -293,6 +293,8 @@
 
     if (n == -1) {
       if (errno == EINTR) {
+       /* EINTR can happen sometimes, especially when compiling with -pg.
+        * Generally we just want to run select again. */
        freelog(LOG_DEBUG, "select() returned EINTR");
        continue;
       }
@@ -830,8 +832,13 @@
   tv.tv_sec = 0;
   tv.tv_usec = 0;
 
-  if (select(socklan + 1, &readfs, NULL, &exceptfs, &tv) == -1) {
-    freelog(LOG_ERROR, "select failed: %s", mystrerror());
+  while (select(socklan + 1, &readfs, NULL, &exceptfs, &tv) == -1) {
+    if (errno != EINTR) {
+      freelog(LOG_ERROR, "select failed: %s", mystrerror());
+      return lan_servers;
+    }
+    /* EINTR can happen sometimes, especially when compiling with -pg.
+     * Generally we just want to run select again. */
   }
 
   if (!FD_ISSET(socklan, &readfs)) {
Index: common/connection.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/connection.c,v
retrieving revision 1.44
diff -u -r1.44 connection.c
--- common/connection.c 14 Nov 2004 23:21:39 -0000      1.44
+++ common/connection.c 17 Nov 2004 18:27:37 -0000
@@ -205,7 +205,13 @@
     tv.tv_sec = 0; tv.tv_usec = 0;
 
     if (select(pc->sock+1, NULL, &writefs, &exceptfs, &tv) <= 0) {
-      break;
+      if (errno != EINTR) {
+       break;
+      } else {
+       /* EINTR can happen sometimes, especially when compiling with -pg.
+        * Generally we just want to run select again. */
+       continue;
+      }
     }
 
     if (FD_ISSET(pc->sock, &exceptfs)) {
Index: server/sernet.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sernet.c,v
retrieving revision 1.127
diff -u -r1.127 sernet.c
--- server/sernet.c     16 Nov 2004 17:56:54 -0000      1.127
+++ server/sernet.c     17 Nov 2004 18:27:38 -0000
@@ -1005,8 +1005,13 @@
   tv.tv_sec = 0;
   tv.tv_usec = 0;
 
-  if (select(socklan + 1, &readfs, NULL, &exceptfs, &tv) == -1) {
-    freelog(LOG_ERROR, "select failed: %s", mystrerror());
+  while (select(socklan + 1, &readfs, NULL, &exceptfs, &tv) == -1) {
+    if (errno != EINTR) {
+      freelog(LOG_ERROR, "select failed: %s", mystrerror());
+      return;
+    }
+    /* EINTR can happen sometimes, especially when compiling with -pg.
+     * Generally we just want to run select again. */
   }
 
   if (FD_ISSET(socklan, &readfs)) {
Index: utility/support.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/support.c,v
retrieving revision 1.28
diff -u -r1.28 support.c
--- utility/support.c   17 May 2004 02:16:15 -0000      1.28
+++ utility/support.c   17 Nov 2004 18:27:38 -0000
@@ -185,6 +185,8 @@
   struct timeval tv;
   tv.tv_sec=0;
   tv.tv_usec=usec;
+  /* FIXME: an interrupt can cause an EINTR return here.  In that case we
+   * need to have another select call. */
   select(0, NULL, NULL, NULL, &tv);
 #endif
 #endif

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#9032) Bug: odd "select" error message, Jason Short <=