? cvsservice/Debug Index: cvsservice/Service.cpp =================================================================== RCS file: /usr/local/cvs/cvsnt/cvsservice/Service.cpp,v retrieving revision 1.27 diff -u -r1.27 Service.cpp --- cvsservice/Service.cpp 29 Aug 2002 14:04:40 -0000 1.27 +++ cvsservice/Service.cpp 8 Sep 2002 02:49:12 -0000 @@ -6,6 +6,9 @@ #include #include #include +#include +#include +#include #include "../windows-NT/version_no.h" #include "../windows-NT/version_fu.h" @@ -28,6 +31,7 @@ static void ReportError(BOOL bError, LPCTSTR szError, ...); static DWORD CALLBACK DoCvsThread(LPVOID lpParam); static DWORD CALLBACK DoPipeThread(LPVOID lpParam); +static void ChangeServiceDirectory(char *argv[]); static DWORD g_dwCurrentState; static SERVICE_STATUS_HANDLE g_hService; @@ -36,6 +40,8 @@ static BOOL g_bTestMode = FALSE; static int authserver_port = 2401; + + int main(int argc, char* argv[]) { SC_HANDLE hSCManager = NULL, hService = NULL; @@ -46,10 +52,12 @@ { NULL, NULL } }; + if(argc==1) { // Attempt to start service. If this fails we're probably - // not running as a service + // not running as a service + ChangeServiceDirectory(argv); if(!StartServiceCtrlDispatcher(ServiceTable)) return 0; } if(argc!=2 || (strcmp(argv[1],"-i") && strcmp(argv[1],"-u") && strcmp(argv[1],"-test") && strcmp(argv[1],"-v") )) @@ -130,6 +138,18 @@ ServiceMain(999,NULL); } return 0; +} + +void ChangeServiceDirectory(char *argv[]) { + // Set the working directory to be the directory that + // this executable is located at. + char *servicePath = strdup(argv[0]); + char *lastSeperatorPtr = strrchr( servicePath, '\\' ); + if( lastSeperatorPtr ) { + *lastSeperatorPtr=NULL; + _chdir(servicePath); + } + free(servicePath); } void CALLBACK ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv)