(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:
Ron Koenderink 2005-05-03 00:06:10 +00:00
parent 9f27f5b02a
commit 921fba6532
2 changed files with 12 additions and 16 deletions

View file

@ -41,22 +41,14 @@
int int
install_service(char *program_name, char *service_name, char *config_file) install_service(char *program_name, char *service_name, char *config_file)
{ {
char strDir[1024];
HANDLE schSCManager,schService; HANDLE schSCManager,schService;
LPCTSTR lpszBinaryPathName;
SERVICE_DESCRIPTION sdBuf; SERVICE_DESCRIPTION sdBuf;
if (strrchr(program_name,'\\') == NULL) { if (config_file == NULL)
GetCurrentDirectory(sizeof(strDir), strDir); config_file = _fullpath(NULL, "econfig", 0);
strcat(strDir, "\\");
strcat(strDir, program_name);
} else
strcpy(strDir, program_name);
if (config_file != NULL) { _snprintf(&program_name[strlen(program_name)], _MAX_PATH-strlen(program_name), " -e %s",
strcat(strDir, " -e "); config_file);
strcat(strDir, config_file);
}
if (service_name == NULL) if (service_name == NULL)
service_name = DEFAULT_SERVICE_NAME; service_name = DEFAULT_SERVICE_NAME;
@ -70,8 +62,6 @@ install_service(char *program_name, char *service_name, char *config_file)
return EXIT_FAILURE; return EXIT_FAILURE;
} }
lpszBinaryPathName = strDir;
schService = CreateService(schSCManager, schService = CreateService(schSCManager,
service_name, service_name,
service_name, /* service name to display */ 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_WIN32_OWN_PROCESS, /* service type */
SERVICE_AUTO_START, /* start type */ SERVICE_AUTO_START, /* start type */
SERVICE_ERROR_NORMAL, /* error control type */ SERVICE_ERROR_NORMAL, /* error control type */
lpszBinaryPathName, /* service's binary */ program_name, /* service's binary */
NULL, /* no load ordering group */ NULL, /* no load ordering group */
NULL, /* no tag identifier */ NULL, /* no tag identifier */
NULL, /* database service dependency */ NULL, /* database service dependency */

View file

@ -117,6 +117,7 @@ main(int argc, char **argv)
int flags = 0; int flags = 0;
#if defined(_WIN32) #if defined(_WIN32)
int install_service_set = 0; int install_service_set = 0;
char *program_name = NULL;
char *service_name = NULL; char *service_name = NULL;
int remove_service_set = 0; int remove_service_set = 0;
#endif #endif
@ -197,6 +198,11 @@ main(int argc, char **argv)
#if defined(_WIN32) #if defined(_WIN32)
if (remove_service_set) if (remove_service_set)
return remove_service(service_name); 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 */ #endif /* _WIN32 */
if (emp_config(config_file) < 0) if (emp_config(config_file) < 0)
@ -208,7 +214,7 @@ main(int argc, char **argv)
#if defined(_WIN32) #if defined(_WIN32)
if (install_service_set) if (install_service_set)
return install_service(argv[0], service_name, config_file); return install_service(program_name, service_name, config_file);
#endif /* _WIN32 */ #endif /* _WIN32 */
init_server(); init_server();