3 * $Id: win32.cc,v 1.10 2003/08/03 21:02:41 robertc Exp $
5 * * * * * * * * Legal stuff * * * * * * *
7 * (C) 2001 Guido Serassio <serassio@libero.it>,
8 * inspired by previous work by Romeo Anghelache & Eric Stern.
10 * SQUID Web Proxy Cache http://www.squid-cache.org/
11 * ----------------------------------------------------------
13 * Squid is the result of efforts by numerous individuals from
14 * the Internet community; see the CONTRIBUTORS file for full
15 * details. Many organizations have provided support for Squid's
16 * development; see the SPONSORS file for full details. Squid is
17 * Copyrighted (C) 2001 by the Regents of the University of
18 * California; see the COPYRIGHT file for full details. Squid
19 * incorporates software developed and/or copyrighted by other
20 * sources; see the CREDITS file for full details.
22 * This program is free software; you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation; either version 2 of the License, or
25 * (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
43 #include "squid_windows.h"
45 static unsigned int GetOSVersion();
46 void WIN32_svcstatusupdate(DWORD
, DWORD
);
47 void WINAPI
WIN32_svcHandler(DWORD
);
49 static int WIN32_StoreKey(const char *, DWORD
, unsigned char *, int);
50 static int WIN32_create_key(void);
51 static void WIN32_build_argv (char *);
53 extern "C" void WINAPI
SquidMain(DWORD
, char **);
55 static int Squid_Aborting
= 0;
57 static SERVICE_STATUS svcStatus
;
58 static SERVICE_STATUS_HANDLE svcHandle
;
59 static int WIN32_argc
;
60 static char ** WIN32_argv
;
61 static char * WIN32_module_name
;
64 static char VENDORString
[] = VENDOR
;
65 #define SOFTWARENAME "Squid"
66 static char SOFTWARENAMEString
[] = SOFTWARENAME
;
67 #define WIN32_VERSION "3.0"
68 static char WIN32_VERSIONString
[] = WIN32_VERSION
;
69 #define SOFTWARE "SOFTWARE"
70 static char SOFTWAREString
[] = SOFTWARE
;
71 #define COMMANDLINE "CommandLine"
72 #define CONFIGFILE "ConfigFile"
73 #undef ChangeServiceConfig2
74 typedef BOOL (WINAPI
* PFChangeServiceConfig2
) (SC_HANDLE
, DWORD
, LPVOID
);
76 #define CHANGESERVICECONFIG2 "ChangeServiceConfig2W"
78 #define CHANGESERVICECONFIG2 "ChangeServiceConfig2A"
80 static SC_ACTION Squid_SCAction
[] = { { SC_ACTION_RESTART
, 60000 } };
81 static char Squid_ServiceDescriptionString
[] = SOFTWARENAME
" " VERSION
" WWW Proxy Server";
82 static SERVICE_DESCRIPTION Squid_ServiceDescription
= { Squid_ServiceDescriptionString
};
83 static SERVICE_FAILURE_ACTIONS Squid_ServiceFailureActions
= { INFINITE
, NULL
, NULL
, 1, Squid_SCAction
};
84 static char REGKEY
[256]=SOFTWARE
"\\"VENDOR
"\\"SOFTWARENAME
"\\"WIN32_VERSION
"\\";
85 static char *keys
[] = {
86 SOFTWAREString
, /* key[0] */
87 VENDORString
, /* key[1] */
88 SOFTWARENAMEString
, /* key[2] */
89 WIN32_VERSIONString
, /* key[3] */
95 /* ====================================================================== */
97 /* ====================================================================== */
101 WIN32_create_key(void)
109 hKey
= HKEY_LOCAL_MACHINE
;
113 /* Walk the tree, creating at each stage if necessary */
115 while (keys
[index
]) {
116 unsigned long result
;
117 rv
= RegCreateKeyEx(hKey
, keys
[index
], /* subkey */
120 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hKeyNext
, &result
);
122 if (rv
!= ERROR_SUCCESS
) {
123 fprintf(stderr
, "RegCreateKeyEx(%s),%d\n", keys
[index
], (int) rv
);
127 /* Close the old key */
128 rv
= RegCloseKey(hKey
);
130 if (rv
!= ERROR_SUCCESS
) {
131 fprintf(stderr
, "RegCloseKey %d\n", (int) rv
);
134 /* Keep error status from RegCreateKeyEx, if any */
147 if (keys
[index
] == NULL
) {
148 /* Close the final key we opened, if we walked the entire
151 rv
= RegCloseKey(hKey
);
153 if (rv
!= ERROR_SUCCESS
) {
154 fprintf(stderr
, "RegCloseKey %d\n", (int) rv
);
157 /* Keep error status from RegCreateKeyEx, if any */
167 WIN32_StoreKey(const char *key
, DWORD type
, unsigned char *value
,
174 rv
= RegOpenKeyEx(HKEY_LOCAL_MACHINE
, REGKEY
, 0, KEY_WRITE
, &hKey
);
176 if (rv
== ERROR_FILE_NOT_FOUND
) {
177 /* Key could not be opened -- try to create it
180 if (WIN32_create_key() < 0) {
181 /* Creation failed (error already reported) */
185 /* Now it has been created we should be able to open it
187 rv
= RegOpenKeyEx(HKEY_LOCAL_MACHINE
, REGKEY
, 0, KEY_WRITE
, &hKey
);
189 if (rv
== ERROR_FILE_NOT_FOUND
) {
190 fprintf(stderr
, "Registry does not contain key %s after creation\n",
196 if (rv
!= ERROR_SUCCESS
) {
197 fprintf(stderr
, "RegOpenKeyEx HKLM\\%s, %d\n", REGKEY
, (int) rv
);
201 /* Now set the value and data */
202 rv
= RegSetValueEx(hKey
, key
, /* value key name */
205 value
, /* value data */
206 (DWORD
) value_size
); /* for size of "value" */
208 retval
= 0; /* Return value */
210 if (rv
!= ERROR_SUCCESS
) {
211 fprintf(stderr
, "RegQueryValueEx(key %s),%d\n", key
, (int) rv
);
214 fprintf(stderr
, "Registry stored HKLM\\%s\\%s value %s\n",
217 type
== REG_SZ
? value
: (unsigned char *) "(not displayable)");
220 /* Make sure we close the key even if there was an error storing
223 rv
= RegCloseKey(hKey
);
225 if (rv
!= ERROR_SUCCESS
) {
226 fprintf(stderr
, "RegCloseKey HKLM\\%s, %d\n", REGKEY
, (int) rv
);
229 /* Keep error status from RegQueryValueEx, if any */
244 safe_free(WIN32_OS_string
);
245 memset(&osvi
, '\0', sizeof(OSVERSIONINFO
));
246 osvi
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
247 GetVersionEx((OSVERSIONINFO
*) & osvi
);
249 switch (osvi
.dwPlatformId
) {
251 case VER_PLATFORM_WIN32_NT
:
253 if (osvi
.dwMajorVersion
<= 4) {
254 WIN32_OS_string
= xstrdup("Windows NT");
255 return _WIN_OS_WINNT
;
258 if ((osvi
.dwMajorVersion
== 5) && (osvi
.dwMinorVersion
== 0)) {
259 WIN32_OS_string
= xstrdup("Windows 2000");
260 return _WIN_OS_WIN2K
;
263 if ((osvi
.dwMajorVersion
== 5) && (osvi
.dwMinorVersion
== 1)) {
264 WIN32_OS_string
= xstrdup("Windows XP");
265 return _WIN_OS_WINXP
;
268 if ((osvi
.dwMajorVersion
== 5) && (osvi
.dwMinorVersion
== 2)) {
269 WIN32_OS_string
= xstrdup("Windows Server 2003");
270 return _WIN_OS_WINNET
;
275 case VER_PLATFORM_WIN32_WINDOWS
:
277 if ((osvi
.dwMajorVersion
== 4) && (osvi
.dwMinorVersion
== 0)) {
278 WIN32_OS_string
= xstrdup("Windows 95");
279 return _WIN_OS_WIN95
;
282 if ((osvi
.dwMajorVersion
== 4) && (osvi
.dwMinorVersion
== 10)) {
283 WIN32_OS_string
= xstrdup("Windows 98");
284 return _WIN_OS_WIN98
;
287 if ((osvi
.dwMajorVersion
== 4) && (osvi
.dwMinorVersion
== 90)) {
288 WIN32_OS_string
= xstrdup("Windows Me");
289 return _WIN_OS_WINME
;
294 case VER_PLATFORM_WIN32s
:
295 WIN32_OS_string
= xstrdup("Windows 3.1 with WIN32S");
296 return _WIN_OS_WIN32S
;
303 WIN32_OS_string
= xstrdup("Unknown Windows system");
304 return _WIN_OS_UNKNOWN
;
307 #if USE_WIN32_SERVICE
308 /* Build argv, argc from string passed from Windows. */
309 static void WIN32_build_argv(char *cmd
)
315 WIN32_argv
= (char **) xmalloc ((WIN32_argc
+1) * sizeof (char *));
316 WIN32_argv
[0]=xstrdup(WIN32_module_name
);
317 /* Scan command line until there is nothing left. */
322 if (xisspace(*cmd
)) {
327 /* Found the beginning of an argument. */
331 cmd
++; /* Skip over this character */
333 if (xisspace(*cmd
)) /* End of argument if space */
338 *cmd
++ = '\0'; /* Terminate `word' */
340 /* See if we need to allocate more space for argv */
341 if (WIN32_argc
>= argvlen
) {
342 argvlen
= WIN32_argc
+ 1;
343 WIN32_argv
= (char **) xrealloc (WIN32_argv
, (1 + argvlen
) * sizeof (char *));
346 /* Add word to argv file. */
347 WIN32_argv
[WIN32_argc
++] = word
;
350 WIN32_argv
[WIN32_argc
] = NULL
;
355 /* ====================================================================== */
356 /* PUBLIC FUNCTIONS */
357 /* ====================================================================== */
362 #if USE_WIN32_SERVICE
363 svcStatus
.dwWin32ExitCode
= ERROR_SERVICE_SPECIFIC_ERROR
;
364 svcStatus
.dwServiceSpecificExitCode
= 1;
374 #if USE_WIN32_SERVICE
376 if (!Squid_Aborting
) {
377 svcStatus
.dwCurrentState
= SERVICE_STOPPED
;
378 SetServiceStatus(svcHandle
, &svcStatus
);
386 #if USE_WIN32_SERVICE
387 int WIN32_Subsystem_Init(int * argc
, char *** argv
)
390 WIN32_Subsystem_Init()
393 WIN32_OS_version
= GetOSVersion();
395 if ((WIN32_OS_version
== _WIN_OS_UNKNOWN
) || (WIN32_OS_version
== _WIN_OS_WIN32S
))
398 if (atexit(WIN32_Exit
) != 0)
401 #if USE_WIN32_SERVICE
403 if (WIN32_run_mode
== _WIN_SQUID_RUN_MODE_SERVICE
)
408 if (signal(SIGABRT
, WIN32_Abort
) == SIG_ERR
)
411 /* Register the service Handler function */
413 RegisterServiceCtrlHandler(WIN32_Service_name
,
419 /* Set Process work dir to directory cointaining squid.exe */
420 GetModuleFileName(NULL
, path
, 512);
422 WIN32_module_name
=xstrdup(path
);
424 path
[strlen(path
) - 10] = '\0';
426 if (SetCurrentDirectory(path
) == 0)
429 safe_free(ConfigFile
);
431 /* get config file from Windows Registry */
432 if (RegOpenKey(HKEY_LOCAL_MACHINE
, REGKEY
, &hndKey
) == ERROR_SUCCESS
) {
437 RegQueryValueEx(hndKey
, CONFIGFILE
, NULL
, &Type
, NULL
, &Size
);
439 if (Result
== ERROR_SUCCESS
&& Size
) {
440 ConfigFile
= static_cast<char *>(xmalloc(Size
));
441 RegQueryValueEx(hndKey
, CONFIGFILE
, NULL
, &Type
, (unsigned char *)ConfigFile
,
444 ConfigFile
= xstrdup(DefaultConfigFile
);
451 RegQueryValueEx(hndKey
, COMMANDLINE
, NULL
, &Type
, NULL
, &Size
);
453 if (Result
== ERROR_SUCCESS
&& Size
) {
454 WIN32_Service_Command_Line
= static_cast<char *>(xmalloc(Size
));
455 RegQueryValueEx(hndKey
, COMMANDLINE
, NULL
, &Type
, (unsigned char *)WIN32_Service_Command_Line
,
458 WIN32_Service_Command_Line
= xstrdup("");
462 ConfigFile
= xstrdup(DefaultConfigFile
);
463 WIN32_Service_Command_Line
= xstrdup("");
466 WIN32_build_argv(WIN32_Service_Command_Line
);
469 /* Set Service Status to SERVICE_START_PENDING */
470 svcStatus
.dwServiceType
= SERVICE_WIN32_OWN_PROCESS
;
471 svcStatus
.dwCurrentState
= SERVICE_START_PENDING
;
472 svcStatus
.dwControlsAccepted
=
473 SERVICE_ACCEPT_STOP
| SERVICE_ACCEPT_SHUTDOWN
;
474 svcStatus
.dwWin32ExitCode
= 0;
475 svcStatus
.dwServiceSpecificExitCode
= 0;
476 svcStatus
.dwCheckPoint
= 0;
477 svcStatus
.dwWaitHint
= 10000;
478 SetServiceStatus(svcHandle
, &svcStatus
);
487 #if USE_WIN32_SERVICE
489 WIN32_svcstatusupdate(DWORD svcstate
, DWORD WaitHint
)
491 if (WIN32_run_mode
== _WIN_SQUID_RUN_MODE_SERVICE
) {
492 svcStatus
.dwCheckPoint
++;
493 svcStatus
.dwWaitHint
= WaitHint
;
494 svcStatus
.dwCurrentState
= svcstate
;
495 SetServiceStatus(svcHandle
, &svcStatus
);
500 WIN32_svcHandler(DWORD Opcode
)
506 case _WIN_SQUID_SERVICE_CONTROL_STOP
:
508 case _WIN_SQUID_SERVICE_CONTROL_SHUTDOWN
:
509 /* Do whatever it takes to stop here. */
510 svcStatus
.dwWin32ExitCode
= 0;
511 svcStatus
.dwCurrentState
= SERVICE_STOP_PENDING
;
512 svcStatus
.dwCheckPoint
= 0;
513 svcStatus
.dwWaitHint
= 10000;
516 if (!SetServiceStatus(svcHandle
, &svcStatus
)) {
517 status
= GetLastError();
518 debug(1, 1) ("SetServiceStatus error %ld\n", status
);
521 debug(1, 1) ("Leaving Squid service\n");
524 case _WIN_SQUID_SERVICE_CONTROL_INTERROGATE
:
525 /* Fall through to send current status. */
527 if (!SetServiceStatus(svcHandle
, &svcStatus
)) {
528 status
= GetLastError();
529 debug(1, 1) ("SetServiceStatus error %ld\n", status
);
534 case _WIN_SQUID_SERVICE_CONTROL_ROTATE
:
535 rotate_logs(SIGUSR1
);
538 case _WIN_SQUID_SERVICE_CONTROL_RECONFIGURE
:
542 case _WIN_SQUID_SERVICE_CONTROL_DEBUG
:
543 sigusr2_handle(SIGUSR2
);
546 case _WIN_SQUID_SERVICE_CONTROL_INTERRUPT
:
547 /* Do whatever it takes to stop here. */
548 svcStatus
.dwWin32ExitCode
= 0;
549 svcStatus
.dwCurrentState
= SERVICE_STOP_PENDING
;
550 svcStatus
.dwCheckPoint
= 0;
551 svcStatus
.dwWaitHint
= 10000;
554 if (!SetServiceStatus(svcHandle
, &svcStatus
)) {
555 status
= GetLastError();
556 debug(1, 1) ("SetServiceStatus error %ld\n", status
);
559 debug(1, 1) ("Leaving Squid service\n");
563 debug(1, 1) ("Unrecognized opcode %ld\n", Opcode
);
570 WIN32_RemoveService()
572 SC_HANDLE schService
;
573 SC_HANDLE schSCManager
;
575 if (!WIN32_Service_name
)
576 WIN32_Service_name
= xstrdup(_WIN_SQUID_DEFAULT_SERVICE_NAME
);
578 strcat(REGKEY
, WIN32_Service_name
);
580 keys
[4] = WIN32_Service_name
;
582 schSCManager
= OpenSCManager(NULL
, /* machine (NULL == local) */
583 NULL
, /* database (NULL == default) */
584 SC_MANAGER_ALL_ACCESS
/* access required */
588 fprintf(stderr
, "OpenSCManager failed\n");
590 schService
= OpenService(schSCManager
, WIN32_Service_name
, SERVICE_ALL_ACCESS
);
592 if (schService
== NULL
)
593 fprintf(stderr
, "OpenService failed\n");
595 /* Could not open the service */
597 /* try to stop the service */
599 if (ControlService(schService
, _WIN_SQUID_SERVICE_CONTROL_STOP
,
603 while (QueryServiceStatus(schService
, &svcStatus
)) {
604 if (svcStatus
.dwCurrentState
== SERVICE_STOP_PENDING
)
611 /* now remove the service */
612 if (DeleteService(schService
) == 0)
613 fprintf(stderr
, "DeleteService failed.\n");
615 printf("Service %s deleted successfully.\n",
618 CloseServiceHandle(schService
);
621 CloseServiceHandle(schSCManager
);
626 WIN32_SetServiceCommandLine()
628 if (!WIN32_Service_name
)
629 WIN32_Service_name
= xstrdup(_WIN_SQUID_DEFAULT_SERVICE_NAME
);
631 strcat(REGKEY
, WIN32_Service_name
);
633 keys
[4] = WIN32_Service_name
;
635 /* Now store the Service Command Line in the registry */
636 WIN32_StoreKey(COMMANDLINE
, REG_SZ
, (unsigned char *) WIN32_Command_Line
, strlen(WIN32_Command_Line
) + 1);
640 WIN32_InstallService()
642 SC_HANDLE schService
;
643 SC_HANDLE schSCManager
;
644 char ServicePath
[512];
648 if (!WIN32_Service_name
)
649 WIN32_Service_name
= xstrdup(_WIN_SQUID_DEFAULT_SERVICE_NAME
);
651 strcat(REGKEY
, WIN32_Service_name
);
653 keys
[4] = WIN32_Service_name
;
655 if ((lenpath
= GetModuleFileName(NULL
, ServicePath
, 512)) == 0) {
656 fprintf(stderr
, "Can't get executable path\n");
660 snprintf(szPath
, sizeof(szPath
), "%s %s:%s", ServicePath
, _WIN_SQUID_SERVICE_OPTION
, WIN32_Service_name
);
661 schSCManager
= OpenSCManager(NULL
, /* machine (NULL == local) */
662 NULL
, /* database (NULL == default) */
663 SC_MANAGER_ALL_ACCESS
/* access required */
667 fprintf(stderr
, "OpenSCManager failed\n");
670 schService
= CreateService(schSCManager
, /* SCManager database */
671 WIN32_Service_name
, /* name of service */
672 WIN32_Service_name
, /* name to display */
673 SERVICE_ALL_ACCESS
, /* desired access */
674 SERVICE_WIN32_OWN_PROCESS
, /* service type */
675 SERVICE_AUTO_START
, /* start type */
676 SERVICE_ERROR_NORMAL
, /* error control type */
677 (const char *) szPath
, /* service's binary */
678 NULL
, /* no load ordering group */
679 NULL
, /* no tag identifier */
680 "Tcpip\0AFD\0", /* dependencies */
681 NULL
, /* LocalSystem account */
682 NULL
); /* no password */
685 if ((WIN32_OS_version
== _WIN_OS_WIN2K
) || (WIN32_OS_version
== _WIN_OS_WINXP
)
686 || (WIN32_OS_version
== _WIN_OS_WINNET
)) {
687 HMODULE ADVAPI32Handle
;
688 PFChangeServiceConfig2 ChangeServiceConfig2
;
689 DWORD dwInfoLevel
= SERVICE_CONFIG_DESCRIPTION
;
691 ADVAPI32Handle
= GetModuleHandle("advapi32");
692 ChangeServiceConfig2
= (PFChangeServiceConfig2
) GetProcAddress(ADVAPI32Handle
, CHANGESERVICECONFIG2
);
693 ChangeServiceConfig2(schService
, dwInfoLevel
, &Squid_ServiceDescription
);
694 dwInfoLevel
= SERVICE_CONFIG_FAILURE_ACTIONS
;
695 ChangeServiceConfig2(schService
, dwInfoLevel
, &Squid_ServiceFailureActions
);
698 CloseServiceHandle(schService
);
699 /* Now store the config file location in the registry */
702 ConfigFile
= xstrdup(DefaultConfigFile
);
704 WIN32_StoreKey(CONFIGFILE
, REG_SZ
, (unsigned char *) ConfigFile
, strlen(ConfigFile
) + 1);
706 printf("Squid Cache version %s for %s\n", version_string
,
709 printf("installed successfully as %s Windows System Service.\n",
713 ("To run, start it from the Services Applet of Control Panel.\n");
715 printf("Don't forget to edit squid.conf before starting it.\n\n");
717 fprintf(stderr
, "CreateService failed\n");
721 CloseServiceHandle(schSCManager
);
726 WIN32_sendSignal(int WIN32_signal
)
728 SERVICE_STATUS ssStatus
;
729 DWORD fdwAccess
, fdwControl
;
730 SC_HANDLE schService
;
731 SC_HANDLE schSCManager
;
733 if (!WIN32_Service_name
)
734 WIN32_Service_name
= xstrdup(_WIN_SQUID_DEFAULT_SERVICE_NAME
);
736 schSCManager
= OpenSCManager(NULL
, /* machine (NULL == local) */
737 NULL
, /* database (NULL == default) */
738 SC_MANAGER_ALL_ACCESS
/* access required */
742 fprintf(stderr
, "OpenSCManager failed\n");
746 /* The required service object access depends on the control. */
747 switch (WIN32_signal
) {
749 case 0: /* SIGNULL */
750 fdwAccess
= SERVICE_INTERROGATE
;
751 fdwControl
= _WIN_SQUID_SERVICE_CONTROL_INTERROGATE
;
755 fdwAccess
= SERVICE_USER_DEFINED_CONTROL
;
756 fdwControl
= _WIN_SQUID_SERVICE_CONTROL_ROTATE
;
760 fdwAccess
= SERVICE_USER_DEFINED_CONTROL
;
761 fdwControl
= _WIN_SQUID_SERVICE_CONTROL_DEBUG
;
765 fdwAccess
= SERVICE_USER_DEFINED_CONTROL
;
766 fdwControl
= _WIN_SQUID_SERVICE_CONTROL_RECONFIGURE
;
770 fdwAccess
= SERVICE_STOP
;
771 fdwControl
= _WIN_SQUID_SERVICE_CONTROL_STOP
;
777 fdwAccess
= SERVICE_USER_DEFINED_CONTROL
;
778 fdwControl
= _WIN_SQUID_SERVICE_CONTROL_INTERRUPT
;
785 /* Open a handle to the service. */
786 schService
= OpenService(schSCManager
, /* SCManager database */
787 WIN32_Service_name
, /* name of service */
788 fdwAccess
); /* specify access */
790 if (schService
== NULL
) {
791 fprintf(stderr
, "%s: ERROR: Could not open Service %s\n", appname
,
795 /* Send a control value to the service. */
797 if (!ControlService(schService
, /* handle of service */
798 fdwControl
, /* control value to send */
799 &ssStatus
)) { /* address of status info */
800 fprintf(stderr
, "%s: ERROR: Could not Control Service %s\n",
801 appname
, WIN32_Service_name
);
804 /* Print the service status. */
805 printf("\nStatus of %s Service:\n", WIN32_Service_name
);
806 printf(" Service Type: 0x%lx\n", ssStatus
.dwServiceType
);
807 printf(" Current State: 0x%lx\n", ssStatus
.dwCurrentState
);
808 printf(" Controls Accepted: 0x%lx\n", ssStatus
.dwControlsAccepted
);
809 printf(" Exit Code: %ld\n", ssStatus
.dwWin32ExitCode
);
810 printf(" Service Specific Exit Code: %ld\n",
811 ssStatus
.dwServiceSpecificExitCode
);
812 printf(" Check Point: %ld\n", ssStatus
.dwCheckPoint
);
813 printf(" Wait Hint: %ld\n", ssStatus
.dwWaitHint
);
816 CloseServiceHandle(schService
);
819 CloseServiceHandle(schSCManager
);
822 int main(int argc
, char **argv
)
824 SERVICE_TABLE_ENTRY DispatchTable
[] = {
830 if ((argc
== 2) && strstr(argv
[1], _WIN_SQUID_SERVICE_OPTION
)) {
831 WIN32_run_mode
= _WIN_SQUID_RUN_MODE_SERVICE
;
834 if (!(c
=strchr(argv
[1],':'))) {
835 fprintf(stderr
, "Bad Service Parameter: %s\n", argv
[1]);
839 WIN32_Service_name
= xstrdup(c
+1);
840 DispatchTable
[0].lpServiceName
=WIN32_Service_name
;
841 strcat(REGKEY
, WIN32_Service_name
);
842 keys
[4] = WIN32_Service_name
;
844 if (!StartServiceCtrlDispatcher(DispatchTable
)) {
845 fprintf(stderr
, "StartServiceCtrlDispatcher error = %ld\n",
850 WIN32_run_mode
= _WIN_SQUID_RUN_MODE_INTERACTIVE
;
851 SquidMain(argc
, argv
);
857 #endif /* USE_WIN32_SERVICE */