diff --git a/src/lib/gen/service.c b/src/lib/gen/service.c index 0591bbd0..e9fded49 100644 --- a/src/lib/gen/service.c +++ b/src/lib/gen/service.c @@ -41,22 +41,14 @@ int install_service(char *program_name, char *service_name, char *config_file) { - char strDir[1024]; HANDLE schSCManager,schService; - LPCTSTR lpszBinaryPathName; SERVICE_DESCRIPTION sdBuf; - if (strrchr(program_name,'\\') == NULL) { - GetCurrentDirectory(sizeof(strDir), strDir); - strcat(strDir, "\\"); - strcat(strDir, program_name); - } else - strcpy(strDir, program_name); + if (config_file == NULL) + config_file = _fullpath(NULL, "econfig", 0); - if (config_file != NULL) { - strcat(strDir, " -e "); - strcat(strDir, config_file); - } + _snprintf(&program_name[strlen(program_name)], _MAX_PATH-strlen(program_name), " -e %s", + config_file); if (service_name == NULL) service_name = DEFAULT_SERVICE_NAME; @@ -70,8 +62,6 @@ install_service(char *program_name, char *service_name, char *config_file) return EXIT_FAILURE; } - lpszBinaryPathName = strDir; - schService = CreateService(schSCManager, service_name, service_name, /* service name to display */ @@ -79,7 +69,7 @@ install_service(char *program_name, char *service_name, char *config_file) SERVICE_WIN32_OWN_PROCESS, /* service type */ SERVICE_AUTO_START, /* start type */ SERVICE_ERROR_NORMAL, /* error control type */ - lpszBinaryPathName, /* service's binary */ + program_name, /* service's binary */ NULL, /* no load ordering group */ NULL, /* no tag identifier */ NULL, /* database service dependency */ diff --git a/src/server/main.c b/src/server/main.c index 27862cfb..804bff6d 100644 --- a/src/server/main.c +++ b/src/server/main.c @@ -117,6 +117,7 @@ main(int argc, char **argv) int flags = 0; #if defined(_WIN32) int install_service_set = 0; + char *program_name = NULL; char *service_name = NULL; int remove_service_set = 0; #endif @@ -197,6 +198,11 @@ main(int argc, char **argv) #if defined(_WIN32) if (remove_service_set) return remove_service(service_name); + if (install_service_set) { + program_name = _fullpath(NULL, argv[0], 0); + if (config_file != NULL) + config_file = _fullpath(NULL, config_file, 0); + } #endif /* _WIN32 */ if (emp_config(config_file) < 0) @@ -208,7 +214,7 @@ main(int argc, char **argv) #if defined(_WIN32) if (install_service_set) - return install_service(argv[0], service_name, config_file); + return install_service(program_name, service_name, config_file); #endif /* _WIN32 */ init_server();