Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2004:
[Freeciv-Dev] (PR#8578) client-run servers and KILL/SEGV signals
Home

[Freeciv-Dev] (PR#8578) client-run servers and KILL/SEGV signals

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#8578) client-run servers and KILL/SEGV signals
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 23 Apr 2004 19:55:18 -0700
Reply-to: rt@xxxxxxxxxxx

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

If you start a server through the client, and exit the client "normally" 
(via a quit command or the TERM signal), the client will terminate the 
server.

However if you do a "hard" exit of the client by sending it the KILL or 
SEGV signals (this includes a client segfault) the server won't exit. 
Further, there is no way to do any handling of this in the client AFAIK. 
  I ran into this today when I noticed there were 2 extra civservers 
lying around.

The solution is to handle it in the server.  This patch does that by 
giving the server the "-q 1 -e" command-line parameters.

"-q 1", of course, means "--quitidle 1", meaning the server "quits" 
after 1 second of being idle (i.e., no connections).

However -q doesn't do what it's documented as doing, since of course the 
server doesn't quit - it just restarts.  Therefore we need a new 
command-line parameter to prevent this restarting.  I call this 
--exit-on-end.  If given, the server will exit instead of restarting 
when a game ends.

So when the client gives these parameters to the server, now we won't 
have extra unkilled civserver processees.

As a side note, it's probably desirable for the server to save in this 
situation.  This patch doesn't address that.

As another side note, it's probably possible for the server to determine 
whether the server is being run in "daemon mode" automatically.  But I'm 
not sure what the behavior should be in this case.

jason


? diff
Index: client/connectdlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/connectdlg_common.c,v
retrieving revision 1.9
diff -u -r1.9 connectdlg_common.c
--- client/connectdlg_common.c  24 Apr 2004 00:19:29 -0000      1.9
+++ client/connectdlg_common.c  24 Apr 2004 02:53:25 -0000
@@ -159,7 +159,7 @@
   
   if (server_pid == 0) {
     int fd, argc = 0;
-    const int max_nargs = 10;
+    const int max_nargs = 13;
     char *argv[max_nargs + 1], port_buf[32];
 
     /* inside the child */
@@ -169,6 +169,9 @@
     argv[argc++] = "civserver";
     argv[argc++] = "-p";
     argv[argc++] = port_buf;
+    argv[argc++] = "-q";
+    argv[argc++] = "1";
+    argv[argc++] = "-e";
     if (logfile) {
       argv[argc++] = "--debug";
       argv[argc++] = "3";
Index: server/civserver.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/civserver.c,v
retrieving revision 1.217
diff -u -r1.217 civserver.c
--- server/civserver.c  10 Apr 2004 03:47:49 -0000      1.217
+++ server/civserver.c  24 Apr 2004 02:53:26 -0000
@@ -98,6 +98,8 @@
        showhelp = TRUE;
        break;
       }
+    } else if (is_option("--exit-on-end", argv[inx])) {
+      srvarg.exit_on_end = TRUE;
     } else if ((option = get_option("--info", argv, &inx, argc))) {
       sz_strlcpy(srvarg.extra_metaserver_info, option);
     } else if ((option = get_option("--debug", argv, &inx, argc))) {
@@ -144,6 +146,8 @@
 
     fprintf(stderr, _("  -p, --port PORT\tListen for clients on port PORT\n"));
     fprintf(stderr, _("  -q, --quitidle TIME\tQuit if no players for TIME 
seconds\n"));
+    fprintf(stderr, _("  -e, --exit-on-end\t"
+                     "When a game ends, exit instead of restarting\n"));
     fprintf(stderr, _("  -r, --read FILE\tRead startup script FILE\n"));
     fprintf(stderr, _("  -v, --version\t\tPrint the version number\n"));
     fprintf(stderr, _("Report bugs to <%s>.\n"), BUG_EMAIL_ADDRESS);
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.158
diff -u -r1.158 srv_main.c
--- server/srv_main.c   10 Apr 2004 03:47:50 -0000      1.158
+++ server/srv_main.c   24 Apr 2004 02:53:26 -0000
@@ -1490,7 +1490,8 @@
   /* Run server loop */
   while (TRUE) {
     srv_loop();
-    if (game.timeout == -1) {
+    if (game.timeout == -1 || srvarg.exit_on_end) {
+      /* For autogames or if the -e option is specified, exit the server. */
       server_quit();
     }
 
Index: server/srv_main.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.h,v
retrieving revision 1.18
diff -u -r1.18 srv_main.h
--- server/srv_main.h   10 Apr 2004 03:47:50 -0000      1.18
+++ server/srv_main.h   24 Apr 2004 02:53:26 -0000
@@ -40,6 +40,8 @@
   char extra_metaserver_info[256];
   /* quit if there no players after a given time interval */
   int quitidle;
+  /* exit the server on game ending */
+  bool exit_on_end;
 };
 
 void srv_init(void);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#8578) client-run servers and KILL/SEGV signals, Jason Short <=