(main,install_service) [_WIN32]: Move the construction of full path names
for program file and econfig file for installing a service to main() instead of install_service(). This is because current directory information is lost because of the use of chdir() to move the current directory to the datadir. This change also fixed the setting of a relative directory for the econfig file. The service starts in an arbitrary directory so a relative path can not used by the service.
This commit is contained in:
parent
9f27f5b02a
commit
921fba6532
2 changed files with 12 additions and 16 deletions
|
@ -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 */
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue