------------------------------------------------------------ revno: 13245 revision-id: squid3@treenet.co.nz-20140124015715-kqpjisr3dlse9786 parent: squid3@treenet.co.nz-20140123224739-zwxx2047m3whmcof committer: Amos Jeffries branch nick: trunk timestamp: Thu 2014-01-23 18:57:15 -0700 message: Enable -n command line option for non-Windows Squid builds This command line option is used on Windows to name the service instance of Squid being run and/or managed. At this point it still only has useful effect on Windows, but can now be used by components on other systems as well. Show the running instance service name in cacehmgr and -v output. Also remove _WIN_SQUID_DEFAULT_SERVICE_NAME macro which duplicated the APP_SHORTNAME macro. This changes the Windows service name from Squid to squid (lower case) on future Squid-3 for Windows. ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20140124015715-kqpjisr3dlse9786 # target_branch: http://bzr.squid-cache.org/bzr/squid3/trunk/ # testament_sha1: 4f99d393b0ff6f086f35286d572ac7a8cc5f5596 # timestamp: 2014-01-24 02:53:55 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/trunk/ # base_revision_id: squid3@treenet.co.nz-20140123224739-\ # zwxx2047m3whmcof # # Begin patch === modified file 'src/WinSvc.cc' --- src/WinSvc.cc 2013-12-01 07:37:53 +0000 +++ src/WinSvc.cc 2014-01-24 01:57:15 +0000 @@ -510,7 +510,7 @@ 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; @@ -671,12 +671,12 @@ SC_HANDLE schService; SC_HANDLE schSCManager; - if (!WIN32_Service_name) - WIN32_Service_name = xstrdup(_WIN_SQUID_DEFAULT_SERVICE_NAME); - - strcat(REGKEY, WIN32_Service_name); - - keys[4] = WIN32_Service_name; + if (!service_name) + service_name = xstrdup(APP_SHORTNAME); + + strcat(REGKEY, service_name); + + keys[4] = service_name; schSCManager = OpenSCManager(NULL, /* machine (NULL == local) */ NULL, /* database (NULL == default) */ @@ -686,7 +686,7 @@ 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"); @@ -711,8 +711,7 @@ 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); } @@ -724,12 +723,12 @@ void WIN32_SetServiceCommandLine() { - if (!WIN32_Service_name) - WIN32_Service_name = xstrdup(_WIN_SQUID_DEFAULT_SERVICE_NAME); - - strcat(REGKEY, WIN32_Service_name); - - keys[4] = WIN32_Service_name; + if (!service_name) + service_name = xstrdup(APP_SHORTNAME); + + strcat(REGKEY, 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); @@ -744,19 +743,19 @@ char szPath[512]; int lenpath; - if (!WIN32_Service_name) - WIN32_Service_name = xstrdup(_WIN_SQUID_DEFAULT_SERVICE_NAME); - - strcat(REGKEY, WIN32_Service_name); - - keys[4] = WIN32_Service_name; + if (!service_name) + service_name = xstrdup(APP_SHORTNAME); + + strcat(REGKEY, 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 */ @@ -767,8 +766,8 @@ 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 */ @@ -801,15 +800,9 @@ 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"); @@ -828,8 +821,8 @@ 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) */ @@ -882,12 +875,11 @@ /* 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. */ @@ -896,11 +888,11 @@ 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); @@ -939,10 +931,10 @@ 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", === modified file 'src/defines.h' --- src/defines.h 2013-05-13 22:48:23 +0000 +++ src/defines.h 2014-01-24 01:57:15 +0000 @@ -247,7 +247,6 @@ #define _WIN_SQUID_SERVICE_CONTROL_RECONFIGURE 129 #define _WIN_SQUID_SERVICE_CONTROL_DEBUG 130 #define _WIN_SQUID_SERVICE_CONTROL_INTERRUPT 131 -#define _WIN_SQUID_DEFAULT_SERVICE_NAME "Squid" #define _WIN_SQUID_SERVICE_OPTION "--ntservice" #define _WIN_SQUID_RUN_MODE_INTERACTIVE 0 #define _WIN_SQUID_RUN_MODE_SERVICE 1 === modified file 'src/globals.h' --- src/globals.h 2013-07-27 13:37:29 +0000 +++ src/globals.h 2014-01-24 01:57:15 +0000 @@ -56,6 +56,7 @@ extern const char *version_string; /* VERSION */ extern const char *appname_string; /* PACKAGE */ extern char const *visible_appname_string; /* NULL */ +extern char *service_name; /* xstrdup(APP_SHORTNAME) */ extern const char *fdTypeStr[]; extern const char *hier_strings[]; extern const char *memStatusStr[]; @@ -121,7 +122,6 @@ #if _SQUID_WINDOWS_ extern unsigned int WIN32_OS_version; /* 0 */ extern char *WIN32_OS_string; /* NULL */ -extern char *WIN32_Service_name; /* NULL */ extern char *WIN32_Command_Line; /* NULL */ extern char *WIN32_Service_Command_Line; /* NULL */ extern unsigned int WIN32_run_mode; /* _WIN_SQUID_RUN_MODE_INTERACTIVE */ === modified file 'src/main.cc' --- src/main.cc 2014-01-23 07:59:26 +0000 +++ src/main.cc 2014-01-24 01:57:15 +0000 @@ -157,12 +157,12 @@ 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; @@ -281,11 +281,11 @@ 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" @@ -297,9 +297,9 @@ " -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" @@ -338,7 +338,7 @@ #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 { @@ -508,20 +508,18 @@ } 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) */ @@ -569,6 +567,7 @@ /** \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); @@ -1011,10 +1010,10 @@ #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); === modified file 'src/stat.cc' --- src/stat.cc 2013-12-06 23:52:26 +0000 +++ src/stat.cc 2014-01-24 01:57:15 +0000 @@ -675,10 +675,12 @@ #if _SQUID_WINDOWS_ if (WIN32_run_mode == _WIN_SQUID_RUN_MODE_SERVICE) { storeAppendPrintf(sentry,"\nRunning as %s Windows System Service on %s\n", - WIN32_Service_name, WIN32_OS_string); + Service_name, WIN32_OS_string); storeAppendPrintf(sentry,"Service command line is: %s\n", WIN32_Service_Command_Line); } else storeAppendPrintf(sentry,"Running on %s\n",WIN32_OS_string); +#else + storeAppendPrintf(sentry,"Service Name: %s\n", service_name); #endif storeAppendPrintf(sentry, "Start Time:\t%s\n",