X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=server%2Fservice.c;h=22ec6990544912a1b5f6391da5300857af84430e;hp=5780284d9a37feda5c91a237d2b76813dc2e8de5;hb=59526fbbf2e3b54ce94b3e79e6c7fef9e4f456fb;hpb=55c6ac70550af857d80ef233147dbc986e4095e1 diff --git a/server/service.c b/server/service.c index 5780284..22ec699 100644 --- a/server/service.c +++ b/server/service.c @@ -3,7 +3,19 @@ * Based on code written by * Chas Woodfield, Fretwell Downing Datasystems. * $Log: service.c,v $ - * Revision 1.1 1997-11-07 13:31:52 adam + * Revision 1.4 2000-12-05 19:05:10 adam + * Service automatically starts in the directory from which it was installed. + * + * Revision 1.3 1999/06/10 11:45:30 adam + * Added bend_start, bend_stop handlers and removed pre_init. + * Handlers bend_start/bend_stop are called when service/daemon is + * started/stopped. + * + * Revision 1.2 1999/02/02 13:57:36 adam + * Uses preprocessor define WIN32 instead of WINDOWS to build code + * for Microsoft WIN32. + * + * Revision 1.1 1997/11/07 13:31:52 adam * Added NT Service name part of statserv_options_block. Moved NT * service utility to server library. * @@ -29,11 +41,12 @@ /* For some strange reason it won't work when part of a lib */ /************************************************************/ -#ifdef WINDOWS +#ifdef WIN32 #include #include #include +#include #include "service.h" @@ -222,7 +235,7 @@ void CmdInstallService(int argc, char *argv[], BOOL bAutoStart) SC_HANDLE schService; SC_HANDLE schSCManager; - TCHAR szPath[1024]; + TCHAR szPath[2048]; if (GetModuleFileName(NULL, szPath, 512) == 0) { @@ -231,8 +244,15 @@ void CmdInstallService(int argc, char *argv[], BOOL bAutoStart) else { int i; + char cwdstr[_MAX_PATH]; + + if (!_getcwd(cwdstr, sizeof(cwdstr))) + strcpy (cwdstr, "."); + + strcat (szPath, TEXT(" -runservice \"")); + strcat (szPath, cwdstr); + strcat (szPath, "\""); - strcat (szPath, TEXT(" -runservice")); for (i = 1; i < argc; i++) { /* We will add the given command line arguments to the command */ @@ -404,7 +424,9 @@ BOOL CheckServiceArguments(int argc, char *argv[]) else if (stricmp ("-runservice", argv[i]) == 0) { /* We can carry on, if we reached here */ + chdir(argv[i+1]); argv[i] = ""; + argv[i+1] = ""; return(TRUE); } } @@ -434,8 +456,7 @@ BOOL SetupService(int argc, char *argv[], void *pHandle, LPTSTR pAppName, LPTSTR else { /* Set the console control handler for exiting the program */ -/* SetConsoleCtrlHandler((PHANDLER_ROUTINE)EventHandlerRoutine, TRUE); -*/ + SetConsoleCtrlHandler((PHANDLER_ROUTINE)EventHandlerRoutine, TRUE); /* Now do the main work */ ServiceMain(argc, argv); @@ -465,7 +486,7 @@ BOOL EventHandlerRoutine(DWORD dwCtrlType) case CTRL_SHUTDOWN_EVENT: /* A signal that the system sends to all console processes when the system */ /* We are basically shutting down, so call Service_Delete */ Service_Delete(); - return(TRUE); + return(FALSE); break; default: