(finish_server): New, factored out of termination code. Fixes two
places in service_main() that lacked close_files(). (close_files, loc_NTTerm): Static linkage.
This commit is contained in:
parent
b915edd13c
commit
3f472fc729
3 changed files with 30 additions and 28 deletions
|
@ -45,14 +45,11 @@
|
||||||
#include "commodity.h"
|
#include "commodity.h"
|
||||||
|
|
||||||
/* src/server/main.c */
|
/* src/server/main.c */
|
||||||
extern void close_files(void);
|
|
||||||
extern void panic(int sig);
|
extern void panic(int sig);
|
||||||
extern void shutdwn(int sig);
|
extern void shutdwn(int sig);
|
||||||
extern void init_server(void);
|
extern void init_server(void);
|
||||||
extern void start_server(int);
|
extern void start_server(int);
|
||||||
#if defined(_WIN32)
|
extern void finish_server(void);
|
||||||
extern void loc_NTTerm(void);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* src/lib/ * / *.c
|
* src/lib/ * / *.c
|
||||||
|
|
|
@ -202,13 +202,13 @@ service_main(DWORD argc, LPTSTR *argv)
|
||||||
|
|
||||||
if (service_status_handle == (SERVICE_STATUS_HANDLE)0) {
|
if (service_status_handle == (SERVICE_STATUS_HANDLE)0) {
|
||||||
logerror("RegisterServiceCtrlHandler failed %d\n", GetLastError());
|
logerror("RegisterServiceCtrlHandler failed %d\n", GetLastError());
|
||||||
loc_NTTerm();
|
finish_server()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((hShutdownEvent = CreateEvent(NULL, TRUE, FALSE, NULL)) == NULL) {
|
if ((hShutdownEvent = CreateEvent(NULL, TRUE, FALSE, NULL)) == NULL) {
|
||||||
logerror("CreateEvent for Shutdown failed %d\n", GetLastError());
|
logerror("CreateEvent for Shutdown failed %d\n", GetLastError());
|
||||||
loc_NTTerm();
|
finish_server()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,11 +225,8 @@ service_main(DWORD argc, LPTSTR *argv)
|
||||||
|
|
||||||
empth_exit();
|
empth_exit();
|
||||||
|
|
||||||
/* We should never get here. But, just in case... */
|
CANT_HAPPEN("main thread terminated");
|
||||||
close_files();
|
finish_server();
|
||||||
|
|
||||||
loc_NTTerm();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -68,9 +68,11 @@
|
||||||
|
|
||||||
static void nullify_objects(void);
|
static void nullify_objects(void);
|
||||||
static void init_files(void);
|
static void init_files(void);
|
||||||
|
static void close_files(void);
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
static void loc_NTInit(void);
|
static void loc_NTInit(void);
|
||||||
|
static void loc_NTTerm(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int mainpid = 0;
|
static int mainpid = 0;
|
||||||
|
@ -218,7 +220,7 @@ main(int argc, char **argv)
|
||||||
*/
|
*/
|
||||||
if (GetLastError() != ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) {
|
if (GetLastError() != ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) {
|
||||||
logerror("Failed to dispatch service (%d)", GetLastError());
|
logerror("Failed to dispatch service (%d)", GetLastError());
|
||||||
loc_NTTerm();
|
finish_server();
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -241,12 +243,8 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
empth_exit();
|
empth_exit();
|
||||||
|
|
||||||
/* We should never get here. But, just in case... */
|
CANT_HAPPEN("main thread terminated");
|
||||||
close_files();
|
finish_server();
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
loc_NTTerm();
|
|
||||||
#endif
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,6 +328,18 @@ start_server(int flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Finish serving, release resources.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
finish_server(void)
|
||||||
|
{
|
||||||
|
close_files();
|
||||||
|
#if defined(_WIN32)
|
||||||
|
loc_NTTerm();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
init_files(void)
|
init_files(void)
|
||||||
{
|
{
|
||||||
|
@ -355,7 +365,7 @@ init_files(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
close_files(void)
|
close_files(void)
|
||||||
{
|
{
|
||||||
ef_close(EF_NATION);
|
ef_close(EF_NATION);
|
||||||
|
@ -462,15 +472,13 @@ shutdwn(int sig)
|
||||||
logerror("Server shutting down on signal %d", sig);
|
logerror("Server shutting down on signal %d", sig);
|
||||||
else
|
else
|
||||||
logerror("Server shutting down at Deity's request");
|
logerror("Server shutting down at Deity's request");
|
||||||
close_files();
|
finish_server();
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
loc_NTTerm();
|
if (daemonize)
|
||||||
if (!daemonize)
|
return;
|
||||||
_exit(0);
|
|
||||||
#else
|
|
||||||
_exit(0);
|
|
||||||
#endif
|
#endif
|
||||||
|
_exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -541,7 +549,7 @@ nullify_objects(void)
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
static void
|
static void
|
||||||
loc_NTInit()
|
loc_NTInit(void)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
WORD wVersionRequested;
|
WORD wVersionRequested;
|
||||||
|
@ -555,8 +563,8 @@ loc_NTInit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
loc_NTTerm()
|
loc_NTTerm(void)
|
||||||
{
|
{
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue