From e89fb0bb178524b14535cd56d2fd0cafaac0dbcd Mon Sep 17 00:00:00 2001 From: Ron Koenderink Date: Tue, 29 Nov 2005 03:57:44 +0000 Subject: [PATCH] (close_files, finish_server, panic): 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 | 1 + src/lib/global/init.c | 22 +++++++++++++ src/lib/subs/fileinit.c | 57 ++++++++++++++++++++++++++++++++- src/server/main.c | 71 ++--------------------------------------- 4 files changed, 81 insertions(+), 70 deletions(-) diff --git a/include/prototypes.h b/include/prototypes.h index ccdd26b0..2d93d1af 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -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); diff --git a/src/lib/global/init.c b/src/lib/global/init.c index 3692e717..09f24f32 100644 --- a/src/lib/global/init.c +++ b/src/lib/global/init.c @@ -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]; + } +} diff --git a/src/lib/subs/fileinit.c b/src/lib/subs/fileinit.c index 6b20eeb5..e34dfd75 100644 --- a/src/lib/subs/fileinit.c +++ b/src/lib/subs/fileinit.c @@ -35,6 +35,31 @@ #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(); } diff --git a/src/server/main.c b/src/server/main.c index 02bd3888..90ecf194 100644 --- a/src/server/main.c +++ b/src/server/main.c @@ -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)