(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 SERVICE_H
|
||||||
|
|
||||||
#define DEFAULT_SERVICE_NAME "Empire Server"
|
#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 int remove_service(char *service_name);
|
||||||
extern void WINAPI service_main(DWORD argc, LPTSTR *argv);
|
extern void WINAPI service_main(DWORD argc, LPTSTR *argv);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -471,7 +471,7 @@ empth_exit(void)
|
||||||
if (pThread->bMainThread) {
|
if (pThread->bMainThread) {
|
||||||
/* The main line. Wait forever. */
|
/* The main line. Wait forever. */
|
||||||
while (1) {
|
while (1) {
|
||||||
if (!debug) {
|
if (daemon) {
|
||||||
if (service_stopped())
|
if (service_stopped())
|
||||||
shutdwn(0);
|
shutdwn(0);
|
||||||
Sleep(3);
|
Sleep(3);
|
||||||
|
|
|
@ -39,11 +39,8 @@
|
||||||
#include "../gen/getopt.h"
|
#include "../gen/getopt.h"
|
||||||
#include "optlist.h"
|
#include "optlist.h"
|
||||||
|
|
||||||
|
|
||||||
char *config_file = NULL;
|
|
||||||
|
|
||||||
int
|
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];
|
char strDir[1024];
|
||||||
HANDLE schSCManager,schService;
|
HANDLE schSCManager,schService;
|
||||||
|
@ -219,6 +216,7 @@ service_main(DWORD argc, LPTSTR *argv)
|
||||||
int op;
|
int op;
|
||||||
s_char tbuf[256];
|
s_char tbuf[256];
|
||||||
DWORD status;
|
DWORD status;
|
||||||
|
char *config_file = NULL;
|
||||||
|
|
||||||
optind = 1;
|
optind = 1;
|
||||||
opterr = 1;
|
opterr = 1;
|
||||||
|
|
|
@ -82,6 +82,7 @@ static int mainpid = 0;
|
||||||
* call abort() on internal error.
|
* call abort() on internal error.
|
||||||
*/
|
*/
|
||||||
int debug = 0;
|
int debug = 0;
|
||||||
|
int daemon = 1;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_usage(char *program_name)
|
print_usage(char *program_name)
|
||||||
|
@ -107,9 +108,8 @@ main(int argc, char **argv)
|
||||||
char *service_name = NULL;
|
char *service_name = NULL;
|
||||||
int remove_service_set = 0;
|
int remove_service_set = 0;
|
||||||
int datadir_set = 0;
|
int datadir_set = 0;
|
||||||
#else
|
|
||||||
char *config_file = NULL;
|
|
||||||
#endif
|
#endif
|
||||||
|
char *config_file = NULL;
|
||||||
int op;
|
int op;
|
||||||
s_char tbuf[256];
|
s_char tbuf[256];
|
||||||
|
|
||||||
|
@ -129,6 +129,7 @@ main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
debug++;
|
debug++;
|
||||||
|
daemon = 0;
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
config_file = optarg;
|
config_file = optarg;
|
||||||
|
@ -190,15 +191,10 @@ main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
if (config_file == NULL) {
|
|
||||||
sprintf(tbuf, "%s/econfig", datadir);
|
|
||||||
config_file = tbuf;
|
|
||||||
}
|
|
||||||
emp_config(config_file);
|
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
if (install_service_set)
|
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)
|
if (remove_service_set)
|
||||||
return remove_service(service_name);
|
return remove_service(service_name);
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
@ -207,25 +203,31 @@ main(int argc, char **argv)
|
||||||
sprintf(tbuf, "%s/econfig", datadir);
|
sprintf(tbuf, "%s/econfig", datadir);
|
||||||
config_file = tbuf;
|
config_file = tbuf;
|
||||||
}
|
}
|
||||||
|
emp_config(config_file);
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
if (debug == 0) {
|
if (daemon != 0) {
|
||||||
SERVICE_TABLE_ENTRY DispatchTable[]={{"Empire Server", service_main},{NULL, NULL}};
|
SERVICE_TABLE_ENTRY DispatchTable[]={{"Empire Server", service_main},{NULL, NULL}};
|
||||||
if (StartServiceCtrlDispatcher(DispatchTable))
|
if (StartServiceCtrlDispatcher(DispatchTable))
|
||||||
return 0;
|
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) {
|
if (GetLastError() != ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) {
|
||||||
logerror("Failed to dispatch service (%d)", GetLastError());
|
logerror("Failed to dispatch service (%d)", GetLastError());
|
||||||
printf("Failed to dispatch service (%d)\n", GetLastError());
|
printf("Failed to dispatch service (%d)\n", GetLastError());
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
} else /* start in the foreground */
|
|
||||||
debug = 1;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
daemon = 0;
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
init_server(flags);
|
init_server(flags);
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
if (debug == 0 && flags == 0)
|
if (daemon != 0 && flags == 0)
|
||||||
disassoc();
|
disassoc();
|
||||||
#endif
|
#endif
|
||||||
start_server(flags);
|
start_server(flags);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue