Author: cazfi
Date: Mon Jul 18 20:50:13 2016
New Revision: 33258

URL: http://svn.gna.org/viewcvs/freeciv?rev=33258&view=rev
Log:
Store information if client has has already forced server to die. Make sure 
that server gets killed
if it's still running when client really needs it to shut down.

Reported by Christian Knoke <chrisk>

See bug #24823

Modified:
    trunk/client/connectdlg_common.c

Modified: trunk/client/connectdlg_common.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/connectdlg_common.c?rev=33258&r1=33257&r2=33258&view=diff
==============================================================================
--- trunk/client/connectdlg_common.c    (original)
+++ trunk/client/connectdlg_common.c    Mon Jul 18 20:50:13 2016
@@ -75,10 +75,11 @@
 
 #ifdef HAVE_USABLE_FORK
 static pid_t server_pid = -1;
-#elif WIN32_NATIVE
+#elif FREECIV_MSWINDOWS
 HANDLE server_process = INVALID_HANDLE_VALUE;
 HANDLE loghandle = INVALID_HANDLE_VALUE;
-#endif
+#endif /* HAVE_USABLE_FORK || FREECIV_MSWINDOWS */
+bool server_quitting = FALSE;
 
 static char challenge_fullname[MAX_LEN_PATH];
 static bool client_has_hack = FALSE;
@@ -115,9 +116,12 @@
 **************************************************************************/
 bool is_server_running(void)
 {
+  if (server_quitting) {
+    return FALSE;
+  }
 #ifdef HAVE_USABLE_FORK
   return (server_pid > 0);
-#elif WIN32_NATIVE
+#elif FREECIV_MSWINDOWS
   return (server_process != INVALID_HANDLE_VALUE);
 #else
   return FALSE; /* We've been unable to start one! */
@@ -141,6 +145,32 @@
 ****************************************************************************/
 void client_kill_server(bool force)
 {
+#ifdef HAVE_USABLE_FORK
+  if (server_quitting && server_pid > 0) {
+    /* Already asked to /quit.
+     * If it didn't do that, kill it. */
+    if (waitpid(server_pid, NULL, WUNTRACED) <= 0) {
+      kill(server_pid, SIGTERM);
+      waitpid(server_pid, NULL, WUNTRACED);
+    }
+    server_pid = -1;
+    server_quitting = FALSE;
+  }
+#elif FREECIV_MSWINDOWS
+  if (server_quitting && server_process != INVALID_HANDLE_VALUE) {
+    /* Already asked to /quit.
+     * If it didn't do that, kill it. */
+    TerminateProcess(server_process, 0);
+    CloseHandle(server_process);
+    if (loghandle != INVALID_HANDLE_VALUE) {
+      CloseHandle(loghandle);
+    }
+    server_process = INVALID_HANDLE_VALUE;
+    loghandle = INVALID_HANDLE_VALUE;
+    server_quitting = FALSE;
+  }
+#endif /* FREECIV_MSWINDOWS || HAVE_USABLE_FORK */
+
   if (is_server_running()) {
     if (client.conn.used && client_has_hack) {
       /* This does a "soft" shutdown of the server by sending a /quit.
@@ -156,12 +186,7 @@
        * it could potentially be called when we're connected to an unowned
        * server.  In this case we don't want to kill it. */
       send_chat("/quit");
-#ifdef HAVE_USABLE_FORK
-      server_pid = -1;
-#elif WIN32_NATIVE
-      server_process = INVALID_HANDLE_VALUE;
-      loghandle = INVALID_HANDLE_VALUE;
-#endif
+      server_quitting = TRUE;
     } else if (force) {
       /* Either we already disconnected, or we didn't get control of the
        * server. In either case, the only thing to do is a "hard" kill of
@@ -169,8 +194,8 @@
 #ifdef HAVE_USABLE_FORK
       kill(server_pid, SIGTERM);
       waitpid(server_pid, NULL, WUNTRACED);
-      server_pid = -1; 
-#elif WIN32_NATIVE
+      server_pid = -1;
+#elif FREECIV_MSWINDOWS
       TerminateProcess(server_process, 0);
       CloseHandle(server_process);
       if (loghandle != INVALID_HANDLE_VALUE) {
@@ -178,7 +203,8 @@
       }
       server_process = INVALID_HANDLE_VALUE;
       loghandle = INVALID_HANDLE_VALUE;
-#endif /* WIN32_NATIVE || HAVE_USABLE_FORK */
+#endif /* FREECIV_MSWINDOWS || HAVE_USABLE_FORK */
+      server_quitting = FALSE;
     }
   }
   client_has_hack = FALSE;
@@ -320,6 +346,7 @@
     }
 
     server_pid = fork();
+    server_quitting = FALSE;
 
     if (server_pid == 0) {
       int fd;


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to