]> git.pond.sub.org Git - empserver/commitdiff
(close_files, finish_server, panic):
authorRon Koenderink <rkoenderink@yahoo.ca>
Tue, 29 Nov 2005 03:57:44 +0000 (03:57 +0000)
committerRon Koenderink <rkoenderink@yahoo.ca>
Tue, 29 Nov 2005 03:57:44 +0000 (03:57 +0000)
Rename close_files() to ef_close_srv() and move to fileinit.c.
Replace calls to close_files() with ef_fin_srv().
Call ef_close_srv() from ef_fin_srv().

(ef_close_srv, ef_fin_srv): New.

(init_files, init_server, ef_init_srv):
Rename init_files() to ef_open_srv() and move to fileinit.c.
Remove call to init_files() from init_server() and replace
with a call to ef_open_srv() from ef_init_srv().

(ef_open_srv): New.

(ef_load, init_server, ef_init_srv):
Move the call to ef_load() from init_server() to ef_init_srv().

(global_init, init_server, ef_init_srv):
Move the call to global_init() from init_server() to ef_init_srv().

(nullify_objects, global_init, init_server):
Split nullify_objects() into init_lchr() and init_dchr().
Locate init_lchr() and init_dchr() in init.c.
Add calls to init_lchr() and to init_dchr() from global_init().

(init_lchr(), init_dchr()): New.

include/prototypes.h
src/lib/global/init.c
src/lib/subs/fileinit.c
src/server/main.c

index ccdd26b0ce71394be7e3adf467c6461e27094f03..2d93d1af47a46574c30684e396f4b48746558e75 100644 (file)
@@ -476,6 +476,7 @@ extern int disloan(int, register struct lonstr *);
 extern int distrea(int, register struct trtstr *);
 /* fileinit.c */
 extern void ef_init_srv(void);
+extern void ef_fin_srv(void);
 /* fortdef.c */
 extern int sd(natid, natid, coord, coord, int, int, int);
 extern int dd(natid, natid, coord, coord, int, int);
index 3692e7179bb69e2ec43a0cad6801ac4218f12936..09f24f323a2d8258ed67d9a1570198f8ec08c8c6 100644 (file)
@@ -42,6 +42,8 @@
 static void init_mchr(void);
 static void init_pchr(void);
 static void init_plchr(void);
+static void init_dchr(void);
+static void init_lchr(void);
 
 void
 global_init(void)
@@ -49,6 +51,8 @@ global_init(void)
     init_pchr();
     init_mchr();
     init_plchr();
+    init_dchr();
+    init_lchr();
 }
 
 static void
@@ -89,3 +93,21 @@ init_pchr(void)
        }
     }
 }
+
+static void
+init_dchr()
+{
+    if (opt_BIG_CITY)
+       dchr[SCT_CAPIT] = bigcity_dchr;
+}
+
+static void
+init_lchr()
+{
+    int i;
+
+    for (i = 0; lchr[i].l_name; i++) {
+       /* Fix up the military values */
+       lchr[i].l_mil = lchr[i].l_item[I_MILIT];
+    }
+}
index 6b20eeb53ea6d76dab56457f9b88151345660023..e34dfd75d9d344c84c5ab7dd5ffc2fda3609621b 100644 (file)
 #include "file.h"
 #include "prototypes.h"
 
+static void
+ef_open_srv(void)
+{
+    int failed = 0;
+    failed |= !ef_open(EF_NATION, EFF_MEM);
+    failed |= !ef_open(EF_SECTOR, EFF_MEM);
+    failed |= !ef_open(EF_SHIP, EFF_MEM);
+    failed |= !ef_open(EF_PLANE, EFF_MEM);
+    failed |= !ef_open(EF_LAND, EFF_MEM);
+    failed |= !ef_open(EF_NEWS, 0);
+    failed |= !ef_open(EF_LOAN, 0);
+    failed |= !ef_open(EF_TREATY, 0);
+    failed |= !ef_open(EF_NUKE, EFF_MEM);
+    failed |= !ef_open(EF_POWER, 0);
+    failed |= !ef_open(EF_TRADE, 0);
+    failed |= !ef_open(EF_MAP, EFF_MEM);
+    failed |= !ef_open(EF_BMAP, EFF_MEM);
+    failed |= !ef_open(EF_COMM, 0);
+    failed |= !ef_open(EF_LOST, 0);
+    if (failed) {
+       logerror("Missing files, giving up");
+       exit(EXIT_FAILURE);
+    }
+}
+
 struct fileinit {
     int ef_type;
     void (*init) (int, char *);
@@ -61,11 +86,41 @@ ef_init_srv(void)
 {
     unsigned i;
 
+    if (ef_load() < 0)
+       exit(EXIT_FAILURE);
+
     for (i = 0; i < sizeof(fileinit) / sizeof(fileinit[0]); i++) {
        empfile[fileinit[i].ef_type].init = fileinit[i].init;
        empfile[fileinit[i].ef_type].postread = fileinit[i].postread;
        empfile[fileinit[i].ef_type].prewrite = fileinit[i].prewrite;
     }
-
     ef_init();
+    ef_open_srv();
+    global_init();
+}
+
+static void
+ef_close_srv(void)
+{
+    ef_close(EF_NATION);
+    ef_close(EF_SECTOR);
+    ef_close(EF_SHIP);
+    ef_close(EF_PLANE);
+    ef_close(EF_LAND);
+    ef_close(EF_NEWS);
+    ef_close(EF_LOAN);
+    ef_close(EF_TREATY);
+    ef_close(EF_NUKE);
+    ef_close(EF_POWER);
+    ef_close(EF_TRADE);
+    ef_close(EF_MAP);
+    ef_close(EF_COMM);
+    ef_close(EF_BMAP);
+    ef_close(EF_LOST);
+}
+
+void
+ef_fin_srv(void)
+{
+    ef_close_srv();
 }
index 02bd3888328a4d9fba5227841f4b2990185b3ab1..90ecf19415d26a69ab5332d0febf8d02315c88bb 100644 (file)
@@ -67,9 +67,6 @@
 #include "version.h"
 #include "prototypes.h"
 
-static void nullify_objects(void);
-static void init_files(void);
-static void close_files(void);
 static void create_pidfile(char *, pid_t);
 
 #if defined(_WIN32)
@@ -263,14 +260,9 @@ init_server(void)
     loc_NTInit();
 #endif
     update_policy_check();
-    if (ef_load() < 0)
-       exit(EXIT_FAILURE);
-    nullify_objects();
-    global_init();
     shutdown_init();
     player_init();
     ef_init_srv();
-    init_files();
     io_init();
     init_nreport();
 
@@ -343,7 +335,7 @@ start_server(int flags)
 void
 finish_server(void)
 {
-    close_files();
+    ef_fin_srv();
 #if defined(_WIN32)
     loc_NTTerm();
 #endif
@@ -362,51 +354,6 @@ create_pidfile(char *fname, pid_t pid)
     }
 }
 
-static void
-init_files(void)
-{
-    int failed = 0;
-    failed |= !ef_open(EF_NATION, EFF_MEM);
-    failed |= !ef_open(EF_SECTOR, EFF_MEM);
-    failed |= !ef_open(EF_SHIP, EFF_MEM);
-    failed |= !ef_open(EF_PLANE, EFF_MEM);
-    failed |= !ef_open(EF_LAND, EFF_MEM);
-    failed |= !ef_open(EF_NEWS, 0);
-    failed |= !ef_open(EF_LOAN, 0);
-    failed |= !ef_open(EF_TREATY, 0);
-    failed |= !ef_open(EF_NUKE, EFF_MEM);
-    failed |= !ef_open(EF_POWER, 0);
-    failed |= !ef_open(EF_TRADE, 0);
-    failed |= !ef_open(EF_MAP, EFF_MEM);
-    failed |= !ef_open(EF_BMAP, EFF_MEM);
-    failed |= !ef_open(EF_COMM, 0);
-    failed |= !ef_open(EF_LOST, 0);
-    if (failed) {
-       logerror("Missing files, giving up");
-       exit(EXIT_FAILURE);
-    }
-}
-
-static void
-close_files(void)
-{
-    ef_close(EF_NATION);
-    ef_close(EF_SECTOR);
-    ef_close(EF_SHIP);
-    ef_close(EF_PLANE);
-    ef_close(EF_LAND);
-    ef_close(EF_NEWS);
-    ef_close(EF_LOAN);
-    ef_close(EF_TREATY);
-    ef_close(EF_NUKE);
-    ef_close(EF_POWER);
-    ef_close(EF_TRADE);
-    ef_close(EF_MAP);
-    ef_close(EF_COMM);
-    ef_close(EF_BMAP);
-    ef_close(EF_LOST);
-}
-
 /* we're going down.  try to close the files at least */
 #if !defined(_WIN32)
 void
@@ -423,7 +370,7 @@ panic(int sig)
     sigaction(SIGFPE, &act, NULL);
     logerror("server received fatal signal %d", sig);
     log_last_commands();
-    close_files();
+    ef_fin_srv();
     if (CANT_HAPPEN(sig != SIGBUS && sig != SIGSEGV
                    && sig != SIGILL && sig != SIGFPE))
        _exit(1);
@@ -482,20 +429,6 @@ shutdwn(int sig)
     _exit(0);
 }
 
-
-static void
-nullify_objects(void)
-{
-    int i;
-
-    if (opt_BIG_CITY)
-       dchr[SCT_CAPIT] = bigcity_dchr;
-    for (i = 0; lchr[i].l_name; i++) {
-       /* Fix up the military values */
-       lchr[i].l_mil = lchr[i].l_item[I_MILIT];
-    }
-}
-
 #if defined(_WIN32)
 static void
 loc_NTInit(void)