(main,service_main) [_WIN32]: Fix config_file for WIN32.
(main,service_main,empth_exit) [_WIN32]: Add daemon flag. Separate the debug_flag into two separate flags, one for debugging (debug) and controlling the daemon processing (daemon).
This commit is contained in:
parent
830c171dd2
commit
d1d7028fc7
4 changed files with 20 additions and 20 deletions
|
@ -35,9 +35,9 @@
|
|||
#define SERVICE_H
|
||||
|
||||
#define DEFAULT_SERVICE_NAME "Empire Server"
|
||||
extern char *config_file;
|
||||
|
||||
extern int install_service(char *program_name, char *service_name, int datadir_set);
|
||||
extern int install_service(char *program_name, char *service_name,
|
||||
int datadir_set, char *config_file);
|
||||
extern int remove_service(char *service_name);
|
||||
extern void WINAPI service_main(DWORD argc, LPTSTR *argv);
|
||||
#endif
|
||||
|
|
|
@ -471,7 +471,7 @@ empth_exit(void)
|
|||
if (pThread->bMainThread) {
|
||||
/* The main line. Wait forever. */
|
||||
while (1) {
|
||||
if (!debug) {
|
||||
if (daemon) {
|
||||
if (service_stopped())
|
||||
shutdwn(0);
|
||||
Sleep(3);
|
||||
|
|
|
@ -39,11 +39,8 @@
|
|||
#include "../gen/getopt.h"
|
||||
#include "optlist.h"
|
||||
|
||||
|
||||
char *config_file = NULL;
|
||||
|
||||
int
|
||||
install_service(char *program_name, char *service_name, int datadir_set)
|
||||
install_service(char *program_name, char *service_name, int datadir_set, char *config_file)
|
||||
{
|
||||
char strDir[1024];
|
||||
HANDLE schSCManager,schService;
|
||||
|
@ -219,6 +216,7 @@ service_main(DWORD argc, LPTSTR *argv)
|
|||
int op;
|
||||
s_char tbuf[256];
|
||||
DWORD status;
|
||||
char *config_file = NULL;
|
||||
|
||||
optind = 1;
|
||||
opterr = 1;
|
||||
|
|
|
@ -82,6 +82,7 @@ static int mainpid = 0;
|
|||
* call abort() on internal error.
|
||||
*/
|
||||
int debug = 0;
|
||||
int daemon = 1;
|
||||
|
||||
static void
|
||||
print_usage(char *program_name)
|
||||
|
@ -107,9 +108,8 @@ main(int argc, char **argv)
|
|||
char *service_name = NULL;
|
||||
int remove_service_set = 0;
|
||||
int datadir_set = 0;
|
||||
#else
|
||||
char *config_file = NULL;
|
||||
#endif
|
||||
char *config_file = NULL;
|
||||
int op;
|
||||
s_char tbuf[256];
|
||||
|
||||
|
@ -129,6 +129,7 @@ main(int argc, char **argv)
|
|||
break;
|
||||
case 'd':
|
||||
debug++;
|
||||
daemon = 0;
|
||||
break;
|
||||
case 'e':
|
||||
config_file = optarg;
|
||||
|
@ -190,15 +191,10 @@ main(int argc, char **argv)
|
|||
}
|
||||
#endif /* _WIN32 */
|
||||
|
||||
if (config_file == NULL) {
|
||||
sprintf(tbuf, "%s/econfig", datadir);
|
||||
config_file = tbuf;
|
||||
}
|
||||
emp_config(config_file);
|
||||
|
||||
#if defined(_WIN32)
|
||||
if (install_service_set)
|
||||
return install_service(argv[0], service_name, datadir_set);
|
||||
return install_service(argv[0], service_name, datadir_set, config_file);
|
||||
if (remove_service_set)
|
||||
return remove_service(service_name);
|
||||
#endif /* _WIN32 */
|
||||
|
@ -207,25 +203,31 @@ main(int argc, char **argv)
|
|||
sprintf(tbuf, "%s/econfig", datadir);
|
||||
config_file = tbuf;
|
||||
}
|
||||
emp_config(config_file);
|
||||
|
||||
#if defined(_WIN32)
|
||||
if (debug == 0) {
|
||||
if (daemon != 0) {
|
||||
SERVICE_TABLE_ENTRY DispatchTable[]={{"Empire Server", service_main},{NULL, NULL}};
|
||||
if (StartServiceCtrlDispatcher(DispatchTable))
|
||||
return 0;
|
||||
else
|
||||
else {
|
||||
/*
|
||||
* If it is service startup error then exit otherwise
|
||||
* start server in the foreground
|
||||
*/
|
||||
if (GetLastError() != ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) {
|
||||
logerror("Failed to dispatch service (%d)", GetLastError());
|
||||
printf("Failed to dispatch service (%d)\n", GetLastError());
|
||||
exit(EXIT_FAILURE);
|
||||
} else /* start in the foreground */
|
||||
debug = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
daemon = 0;
|
||||
#endif /* _WIN32 */
|
||||
|
||||
init_server(flags);
|
||||
#ifndef _WIN32
|
||||
if (debug == 0 && flags == 0)
|
||||
if (daemon != 0 && flags == 0)
|
||||
disassoc();
|
||||
#endif
|
||||
start_server(flags);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue