VOID WINAPI WIN32_svcHandler(DWORD Opcode) { DWORD status; switch (Opcode) { case _WIN_SQUID_SERVICE_CONTROL_STOP: case _WIN_SQUID_SERVICE_CONTROL_SHUTDOWN: /* Do whatever it takes to stop here. */ svcStatus.dwWin32ExitCode = 0; svcStatus.dwCurrentState = SERVICE_STOP_PENDING; svcStatus.dwCheckPoint = 0; svcStatus.dwWaitHint = 10000; shut_down(SIGTERM); if (!SetServiceStatus(svcHandle, &svcStatus)) { status = GetLastError(); debug(1, 1) ("SetServiceStatus error %ld\n", status); } debug(1, 1) ("Leaving Squid service\n"); return; case _WIN_SQUID_SERVICE_CONTROL_INTERROGATE: /* Fall through to send current status. */ if (!SetServiceStatus(svcHandle, &svcStatus)) { status = GetLastError(); debug(1, 1) ("SetServiceStatus error %ld\n", status); } break; case _WIN_SQUID_SERVICE_CONTROL_ROTATE: rotate_logs(SIGUSR1); break; case _WIN_SQUID_SERVICE_CONTROL_RECONFIGURE: reconfigure(SIGHUP); break; case _WIN_SQUID_SERVICE_CONTROL_DEBUG: sigusr2_handle(SIGUSR2); break; case _WIN_SQUID_SERVICE_CONTROL_INTERRUPT: /* Do whatever it takes to stop here. */ svcStatus.dwWin32ExitCode = 0; svcStatus.dwCurrentState = SERVICE_STOP_PENDING; svcStatus.dwCheckPoint = 0; svcStatus.dwWaitHint = 10000; shut_down(SIGINT); if (!SetServiceStatus(svcHandle, &svcStatus)) { status = GetLastError(); debug(1, 1) ("SetServiceStatus error %ld\n", status); } debug(1, 1) ("Leaving Squid service\n"); break; default: debug(1, 1) ("Unrecognized opcode %ld\n", Opcode); } return; }
static void mainParseOptions(int argc, char *argv[]) { extern char *optarg; int c; while ((c = getopt(argc, argv, "CDFNRSVYXa:d:f:hk:m::sl:u:vz?")) != -1) { switch (c) { case 'C': opt_catch_signals = 0; break; case 'D': opt_dns_tests = 0; break; case 'F': opt_foreground_rebuild = 1; break; case 'N': opt_no_daemon = 1; break; case 'R': opt_reuseaddr = 0; break; case 'S': opt_store_doublecheck = 1; break; case 'V': vhost_mode = 1; break; case 'X': /* force full debugging */ sigusr2_handle(SIGUSR2); break; case 'Y': opt_reload_hit_only = 1; break; case 'a': httpPortNumOverride = atoi(optarg); break; case 'd': opt_debug_stderr = atoi(optarg); break; case 'f': xfree(ConfigFile); ConfigFile = xstrdup(optarg); break; case 'h': usage(); break; case 'k': if ((int) strlen(optarg) < 1) usage(); if (!strncmp(optarg, "reconfigure", strlen(optarg))) opt_send_signal = SIGHUP; else if (!strncmp(optarg, "rotate", strlen(optarg))) #ifdef _SQUID_LINUX_THREADS_ opt_send_signal = SIGQUIT; #else opt_send_signal = SIGUSR1; #endif else if (!strncmp(optarg, "debug", strlen(optarg))) #ifdef _SQUID_LINUX_THREADS_ opt_send_signal = SIGTRAP; #else opt_send_signal = SIGUSR2; #endif else if (!strncmp(optarg, "shutdown", strlen(optarg))) opt_send_signal = SIGTERM; else if (!strncmp(optarg, "interrupt", strlen(optarg))) opt_send_signal = SIGINT; else if (!strncmp(optarg, "kill", strlen(optarg))) opt_send_signal = SIGKILL; else if (!strncmp(optarg, "check", strlen(optarg))) opt_send_signal = 0; /* SIGNULL */ else if (!strncmp(optarg, "parse", strlen(optarg))) opt_parse_cfg_only = 1; /* parse cfg file only */ else usage(); break; case 'm': if (optarg) { #if MALLOC_DBG malloc_debug_level = atoi(optarg); /* NOTREACHED */ break; #else fatal("Need to add -DMALLOC_DBG when compiling to use -mX option"); /* NOTREACHED */ #endif } else { #if XMALLOC_TRACE xmalloc_trace = !xmalloc_trace; #else fatal("Need to configure --enable-xmalloc-debug-trace to use -m option"); #endif } case 'l': opt_syslog_facility = xstrdup(optarg); case 's': #if HAVE_SYSLOG _db_set_syslog(opt_syslog_facility); break; #else fatal("Logging to syslog not available on this platform"); /* NOTREACHED */ #endif case 'u': icpPortNumOverride = atoi(optarg); if (icpPortNumOverride < 0) icpPortNumOverride = 0; break; case 'v': printf("Squid Cache: Version %s\nconfigure options: %s\n", version_string, SQUID_CONFIGURE_OPTIONS); exit(0); /* NOTREACHED */ case 'z': opt_create_swap_dirs = 1; break; case '?': default: usage(); break; }