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

> [EMAIL PROTECTED] - So 09. Sep 2007, 11:23:12]:
> 
> On 09/09/07, Christian Prochaska  wrote:
> >
> > The attached patch
> > moves the my_shutdown_network() call to the end of the server_shutdown()
> > function.
> 
>  server_shutdown() should be renamed as it does more cleanup than
> shutting down possible internal server. my_shutdown_network() needs to
> be called even when there is no server to shutdown.
> 
> 
>  - ML
> 

Updated patch. The exit handler is now called at_exit() and gets
registered in the main() function.

Index: client/civclient.c
===================================================================
--- client/civclient.c	(revision 13553)
+++ client/civclient.c	(working copy)
@@ -55,6 +55,7 @@
 #include "climisc.h"
 #include "clinet.h"
 #include "cma_core.h"		/* kludge */
+#include "connectdlg_common.h"  /* client_kill_server() */
 #include "connectdlg_g.h"
 #include "control.h" 
 #include "dialogs_g.h"
@@ -165,6 +166,15 @@
 }
 
 /**************************************************************************
+ This is called at program exit.
+**************************************************************************/
+static void at_exit(void)
+{
+  client_kill_server(TRUE);
+  my_shutdown_network();
+}
+
+/**************************************************************************
 ...
 **************************************************************************/
 int main(int argc, char *argv[])
@@ -325,6 +335,10 @@
   ui_init();
   charsets_init();
   my_init_network();
+
+  /* register exit handler */ 
+  atexit(at_exit);
+
   chatline_common_init();
   message_options_init();
   init_player_dlg_common();
@@ -379,7 +393,6 @@
 {
   attribute_flush();
   client_remove_all_cli_conn();
-  my_shutdown_network();
 
   if (save_options_on_exit) {
     save_options();
Index: client/connectdlg_common.c
===================================================================
--- client/connectdlg_common.c	(revision 13553)
+++ client/connectdlg_common.c	(working copy)
@@ -171,14 +171,6 @@
   client_has_hack = FALSE;
 }   
 
-/**************************************************************************
- This is called at program exit.
-**************************************************************************/
-static void server_shutdown(void)
-{
-  client_kill_server(TRUE);
-}
-                                                                               
 /**************************************************************** 
 forks a server if it can. returns FALSE is we find we couldn't start
 the server.
@@ -204,17 +196,11 @@
   char logcmdline[512];
   char scriptcmdline[512];
 # endif
-  static bool initialized = FALSE;
 
   /* only one server (forked from this client) shall be running at a time */
   /* This also resets client_has_hack. */
   client_kill_server(TRUE);
   
-  if (!initialized) {
-    atexit(server_shutdown);
-    initialized = TRUE;
-  }
-
   append_output_window(_("Starting server..."));
 
   /* find a free port */ 
Index: client/civclient.c
===================================================================
--- client/civclient.c	(revision 13539)
+++ client/civclient.c	(working copy)
@@ -53,6 +53,7 @@
 #include "climisc.h"
 #include "clinet.h"
 #include "cma_core.h"		/* kludge */
+#include "connectdlg_common.h"  /* client_kill_server() */
 #include "connectdlg_g.h"
 #include "control.h" 
 #include "dialogs_g.h"
@@ -159,6 +160,15 @@
 }
 
 /**************************************************************************
+ This is called at program exit.
+**************************************************************************/
+static void at_exit(void)
+{
+  client_kill_server(TRUE);
+  my_shutdown_network();
+}
+
+/**************************************************************************
 ...
 **************************************************************************/
 int main(int argc, char *argv[])
@@ -306,6 +316,10 @@
   ui_init();
   charsets_init();
   my_init_network();
+
+  /* register exit handler */ 
+  atexit(at_exit);
+
   chatline_common_init();
   init_messages_where();
   init_city_report_data();
@@ -360,7 +374,6 @@
 {
   attribute_flush();
   client_remove_all_cli_conn();
-  my_shutdown_network();
 
   client_game_free();
 
Index: client/connectdlg_common.c
===================================================================
--- client/connectdlg_common.c	(revision 13539)
+++ client/connectdlg_common.c	(working copy)
@@ -178,14 +178,6 @@
   client_has_hack = FALSE;
 }   
 
-/**************************************************************************
- This is called at program exit.
-**************************************************************************/
-static void server_shutdown(void)
-{
-  client_kill_server(TRUE);
-}
-                                                                               
 /**************************************************************** 
 forks a server if it can. returns FALSE is we find we couldn't start
 the server.
@@ -211,17 +203,11 @@
   char logcmdline[512];
   char scriptcmdline[512];
 # endif
-  static bool initialized = FALSE;
 
   /* only one server (forked from this client) shall be running at a time */
   /* This also resets client_has_hack. */
   client_kill_server(TRUE);
   
-  if (!initialized) {
-    atexit(server_shutdown);
-    initialized = TRUE;
-  }
-
   append_output_window(_("Starting server..."));
 
   /* find a free port */ 
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to