return 1;
/* Register the service Handler function */
- svcHandle = RegisterServiceCtrlHandler(WIN32_Service_name, WIN32_svcHandler);
+ svcHandle = RegisterServiceCtrlHandler(service_name, WIN32_svcHandler);
if (svcHandle == 0)
return 1;
SC_HANDLE schService;
SC_HANDLE schSCManager;
- if (!WIN32_Service_name)
- WIN32_Service_name = xstrdup(_WIN_SQUID_DEFAULT_SERVICE_NAME);
+ if (!service_name)
+ service_name = xstrdup(APP_SHORTNAME);
- strcat(REGKEY, WIN32_Service_name);
+ strcat(REGKEY, service_name);
- keys[4] = WIN32_Service_name;
+ keys[4] = service_name;
schSCManager = OpenSCManager(NULL, /* machine (NULL == local) */
NULL, /* database (NULL == default) */
if (!schSCManager)
fprintf(stderr, "OpenSCManager failed\n");
else {
- schService = OpenService(schSCManager, WIN32_Service_name, SERVICE_ALL_ACCESS);
+ schService = OpenService(schSCManager, service_name, SERVICE_ALL_ACCESS);
if (schService == NULL)
fprintf(stderr, "OpenService failed\n");
if (DeleteService(schService) == 0)
fprintf(stderr, "DeleteService failed.\n");
else
- printf("Service %s deleted successfully.\n",
- WIN32_Service_name);
+ printf("Service %s deleted successfully.\n", service_name);
CloseServiceHandle(schService);
}
void
WIN32_SetServiceCommandLine()
{
- if (!WIN32_Service_name)
- WIN32_Service_name = xstrdup(_WIN_SQUID_DEFAULT_SERVICE_NAME);
+ if (!service_name)
+ service_name = xstrdup(APP_SHORTNAME);
- strcat(REGKEY, WIN32_Service_name);
+ strcat(REGKEY, service_name);
- keys[4] = WIN32_Service_name;
+ keys[4] = service_name;
/* Now store the Service Command Line in the registry */
WIN32_StoreKey(COMMANDLINE, REG_SZ, (unsigned char *) WIN32_Command_Line, strlen(WIN32_Command_Line) + 1);
char szPath[512];
int lenpath;
- if (!WIN32_Service_name)
- WIN32_Service_name = xstrdup(_WIN_SQUID_DEFAULT_SERVICE_NAME);
+ if (!service_name)
+ service_name = xstrdup(APP_SHORTNAME);
- strcat(REGKEY, WIN32_Service_name);
+ strcat(REGKEY, service_name);
- keys[4] = WIN32_Service_name;
+ keys[4] = service_name;
if ((lenpath = GetModuleFileName(NULL, ServicePath, 512)) == 0) {
fprintf(stderr, "Can't get executable path\n");
exit(1);
}
- snprintf(szPath, sizeof(szPath), "%s %s:%s", ServicePath, _WIN_SQUID_SERVICE_OPTION, WIN32_Service_name);
+ snprintf(szPath, sizeof(szPath), "%s %s:%s", ServicePath, _WIN_SQUID_SERVICE_OPTION, service_name);
schSCManager = OpenSCManager(NULL, /* machine (NULL == local) */
NULL, /* database (NULL == default) */
SC_MANAGER_ALL_ACCESS /* access required */
exit(1);
} else {
schService = CreateService(schSCManager, /* SCManager database */
- WIN32_Service_name, /* name of service */
- WIN32_Service_name, /* name to display */
+ service_name, /* name of service */
+ service_name, /* name to display */
SERVICE_ALL_ACCESS, /* desired access */
SERVICE_WIN32_OWN_PROCESS, /* service type */
SERVICE_AUTO_START, /* start type */
WIN32_StoreKey(CONFIGFILE, REG_SZ, (unsigned char *) ConfigFile, strlen(ConfigFile) + 1);
- printf("Squid Cache version %s for %s\n", version_string,
- CONFIG_HOST_TYPE);
-
- printf("installed successfully as %s Windows System Service.\n",
- WIN32_Service_name);
-
- printf
- ("To run, start it from the Services Applet of Control Panel.\n");
-
+ printf("Squid Cache version %s for %s\n", version_string, CONFIG_HOST_TYPE);
+ printf("installed successfully as %s Windows System Service.\n", service_name);
+ printf("To run, start it from the Services Applet of Control Panel.\n");
printf("Don't forget to edit squid.conf before starting it.\n\n");
} else {
fprintf(stderr, "CreateService failed\n");
SC_HANDLE schService;
SC_HANDLE schSCManager;
- if (!WIN32_Service_name)
- WIN32_Service_name = xstrdup(_WIN_SQUID_DEFAULT_SERVICE_NAME);
+ if (!service_name)
+ service_name = xstrdup(APP_SHORTNAME);
schSCManager = OpenSCManager(NULL, /* machine (NULL == local) */
NULL, /* database (NULL == default) */
/* Open a handle to the service. */
schService = OpenService(schSCManager, /* SCManager database */
- WIN32_Service_name, /* name of service */
+ service_name, /* name of service */
fdwAccess); /* specify access */
if (schService == NULL) {
- fprintf(stderr, "%s: ERROR: Could not open Service %s\n", APP_SHORTNAME,
- WIN32_Service_name);
+ fprintf(stderr, "%s: ERROR: Could not open Service %s\n", APP_SHORTNAME, service_name);
exit(1);
} else {
/* Send a control value to the service. */
fdwControl, /* control value to send */
&ssStatus)) { /* address of status info */
fprintf(stderr, "%s: ERROR: Could not Control Service %s\n",
- APP_SHORTNAME, WIN32_Service_name);
+ APP_SHORTNAME, service_name);
exit(1);
} else {
/* Print the service status. */
- printf("\nStatus of %s Service:\n", WIN32_Service_name);
+ printf("\nStatus of %s Service:\n", service_name);
printf(" Service Type: 0x%lx\n", ssStatus.dwServiceType);
printf(" Current State: 0x%lx\n", ssStatus.dwCurrentState);
printf(" Controls Accepted: 0x%lx\n", ssStatus.dwControlsAccepted);
return 1;
}
- WIN32_Service_name = xstrdup(c+1);
- DispatchTable[0].lpServiceName=WIN32_Service_name;
- strcat(REGKEY, WIN32_Service_name);
- keys[4] = WIN32_Service_name;
+ service_name = xstrdup(c+1);
+ DispatchTable[0].lpServiceName=service_name;
+ strcat(REGKEY, service_name);
+ keys[4] = service_name;
if (!StartServiceCtrlDispatcher(DispatchTable)) {
fprintf(stderr, "StartServiceCtrlDispatcher error = %ld\n",
static int opt_install_service = FALSE;
static int opt_remove_service = FALSE;
-static int opt_signal_service = FALSE;
static int opt_command_line = FALSE;
void WIN32_svcstatusupdate(DWORD, DWORD);
void WINAPI WIN32_svcHandler(DWORD);
#endif
+static int opt_signal_service = FALSE;
static char *opt_syslog_facility = NULL;
static int icpPortNumOverride = 1; /* Want to detect "-u 0" */
static int configured_once = 0;
usage(void)
{
fprintf(stderr,
+ "Usage: %s [-cdhvzCFNRVYX] [-n name] [-s | -l facility] [-f config-file] [-[au] port] [-k signal]"
#if USE_WIN32_SERVICE
- "Usage: %s [-cdhirvzCFNRVYX] [-s | -l facility] [-f config-file] [-[au] port] [-k signal] [-n name] [-O CommandLine]\n"
-#else
- "Usage: %s [-cdhvzCFNRVYX] [-s | -l facility] [-f config-file] [-[au] port] [-k signal]\n"
+ "[-ir] [-O CommandLine]"
#endif
+ "\n"
" -a port Specify HTTP port number (default: %d).\n"
" -d level Write debugging to stderr also.\n"
" -f file Use given config-file instead of\n"
" -k reconfigure|rotate|shutdown|interrupt|kill|debug|check|parse\n"
" Parse configuration file, then send signal to \n"
" running copy (except -k parse) and exit.\n"
+ " -n name Specify service name to use for service operations\n"
+ " default is: " APP_SHORTNAME ".\n"
#if USE_WIN32_SERVICE
- " -n name Specify Windows Service name to use for service operations\n"
- " default is: " _WIN_SQUID_DEFAULT_SERVICE_NAME ".\n"
" -r Removes a Windows Service (see -n option).\n"
#endif
" -s | -l facility\n"
#if USE_WIN32_SERVICE
while ((c = getopt(argc, argv, "CDFNO:RSVYXa:d:f:hik:m::n:rsl:u:vz?")) != -1)
#else
- while ((c = getopt(argc, argv, "CDFNRSYXa:d:f:hk:m::sl:u:vz?")) != -1)
+ while ((c = getopt(argc, argv, "CDFNRSYXa:d:f:hk:m::n:sl:u:vz?")) != -1)
#endif
{
}
break;
-#if USE_WIN32_SERVICE
-
case 'n':
/** \par n
- * Set global option opt_signal_service (to TRUE).
- * Stores the additional parameter given in global WIN32_Service_name */
- xfree(WIN32_Service_name);
-
- WIN32_Service_name = xstrdup(optarg);
-
- opt_signal_service = TRUE;
-
+ * Set global option opt_signal_service (to true).
+ * Stores the additional parameter given in global service_name */
+ // XXX: verify that the new name has ONLY alphanumeric characters
+ xfree(service_name);
+ service_name = xstrdup(optarg);
+ opt_signal_service = true;
break;
+#if USE_WIN32_SERVICE
+
case 'r':
/** \par r
* Set global option opt_remove_service (to TRUE) */
/** \par v
* Display squid version and build information. Then exit. */
printf("Squid Cache: Version %s\n" ,version_string);
+ printf("Service Name: %s\n", service_name);
if (strlen(SQUID_BUILD_INFO))
printf("%s\n",SQUID_BUILD_INFO);
printf( "configure options: %s\n", SQUID_CONFIGURE_OPTIONS);
#endif
debugs(1, DBG_CRITICAL, "Starting Squid Cache version " << version_string << " for " << CONFIG_HOST_TYPE << "...");
+ debugs(1, DBG_CRITICAL, "Service Name: " << service_name);
#if _SQUID_WINDOWS_
if (WIN32_run_mode == _WIN_SQUID_RUN_MODE_SERVICE) {
- debugs(1, DBG_CRITICAL, "Running as " << WIN32_Service_name << " Windows System Service on " << WIN32_OS_string);
debugs(1, DBG_CRITICAL, "Service command line is: " << WIN32_Service_Command_Line);
} else
debugs(1, DBG_CRITICAL, "Running on " << WIN32_OS_string);