Complete.Org: Mailing Lists: Archives: freeciv-dev: June 2005:
[Freeciv-Dev] Re: (PR#13307) server crash with closed stdin
Home

[Freeciv-Dev] Re: (PR#13307) server crash with closed stdin

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#13307) server crash with closed stdin
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 23 Jun 2005 09:07:14 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13307 >

Jason Short wrote:
> <URL: http://bugs.freeciv.org/Ticket/Display.html?id=13307 >
> 
> If you compile freeciv without readline (undefine the *READLINE* entries
> in config.h) and then run it with closed stdin (*not* the same as
> running `civserver </dev/null`) then the server will die.
> 
> #0  0x40085921 in kill () from /lib/libc.so.6
> #1  0x401a707b in pthread_kill () from /lib/libpthread.so.0
> #2  0x401a7420 in raise () from /lib/libpthread.so.0
> #3  0x400855d3 in raise () from /lib/libc.so.6
> #4  0x40086988 in abort () from /lib/libc.so.6
> #5  0x4007ecf0 in __assert_fail () from /lib/libc.so.6
> #6  0x0804bee4 in real_die (file=0x810f051 "sernet.c", line=604,
> format=0x810f175 "read from stdin failed") at shared.c:675
> #7  0x08050860 in sniff_packets () at sernet.c:604
> #8  0x08052928 in srv_main () at srv_main.c:1694
> #9  0x0804a222 in main (argc=5, argv=0xbffff7d4) at civserver.c:210

To reproduce: apply the stdin.diff patch.  Configure with
--without-readline (or edit config.h to comment out the READLINE entries).

The stdin_fix.diff patch fixes it.  This should be for both branches.

-jason

? server/st2HbzVX
Index: server/civserver.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/civserver.c,v
retrieving revision 1.230
diff -u -r1.230 civserver.c
--- server/civserver.c  3 Feb 2005 08:04:55 -0000       1.230
+++ server/civserver.c  23 Jun 2005 15:49:12 -0000
@@ -77,6 +77,7 @@
 }
 #endif
 
+#include <unistd.h>
 /**************************************************************************
  Entry point for Freeciv server.  Basically, does two things:
   1. Parses command-line arguments (possibly dialog, on mac).
@@ -89,6 +90,10 @@
   bool showvers = FALSE;
   char *option = NULL;
 
+  close(0);
+  close(1);
+  close(2);
+
   /* Load win32 post-crash debugger */
 #ifdef WIN32_NATIVE
 # ifndef NDEBUG
Index: server/sernet.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sernet.c,v
retrieving revision 1.141
diff -u -r1.141 sernet.c
--- server/sernet.c     5 May 2005 18:32:53 -0000       1.141
+++ server/sernet.c     23 Jun 2005 16:05:31 -0000
@@ -656,11 +656,8 @@
       char buf[BUF_SIZE + 1];
       char *buf_internal;
       
-      if ((didget = read(0, buf, BUF_SIZE)) == -1) {
-       die("read from stdin failed");
-      }
-
-      if (didget == 0) {
+      didget = read(0, buf, BUF_SIZE);
+      if (didget <= 0) {
         handle_stdin_close();
       }
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] Re: (PR#13307) server crash with closed stdin, Jason Short <=