From: hno <> Date: Sun, 27 Apr 2003 06:18:00 +0000 (+0000) Subject: From Guido: X-Git-Tag: SQUID_3_0_PRE1~232 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0e657244670db45e042b203ff28468382a8da6e9;p=thirdparty%2Fsquid.git From Guido: Native Windows port enhancements: - new Windows service command line options and configure support With this patch the Windows service support on Cygwin should be complete. --- diff --git a/configure.in b/configure.in index 2a3d444273..48776d02cd 100644 --- a/configure.in +++ b/configure.in @@ -3,7 +3,7 @@ dnl Configuration input file for Squid dnl dnl Duane Wessels, wessels@nlanr.net, February 1996 (autoconf v2.9) dnl -dnl $Id: configure.in,v 1.330 2003/04/22 07:38:29 robertc Exp $ +dnl $Id: configure.in,v 1.331 2003/04/27 00:18:00 hno Exp $ dnl dnl dnl @@ -13,7 +13,7 @@ AC_CONFIG_SRCDIR([src/main.cc]) AC_CONFIG_AUX_DIR(cfgaux) AM_INIT_AUTOMAKE(squid, 3.0-DEVEL) AM_CONFIG_HEADER(include/autoconf.h) -AC_REVISION($Revision: 1.330 $)dnl +AC_REVISION($Revision: 1.331 $)dnl AC_PREFIX_DEFAULT(/usr/local/squid) AM_MAINTAINER_MODE @@ -1240,6 +1240,16 @@ AC_ARG_ENABLE(mempools, fi ]) +dnl Enable WIN32 Service compile mode +AC_ARG_ENABLE(win32-service, +[ --enable-win32-service Compile Squid as a WIN32 Service + Works only on Windows NT and Windows 2000 Platforms.], +[ if test "$enableval" = "yes" ; then + echo "Enabling WIN32 run service mode" + AC_DEFINE(USE_WIN32_SERVICE,1,[Define Windows NT & Windows 2000 run service mode]) + fi +]) + SAMBASOURCES='$(top_srcdir)/include/samba' AC_ARG_WITH(samba-sources, diff --git a/src/main.cc b/src/main.cc index b03a533057..285c97a5e0 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,6 +1,6 @@ /* - * $Id: main.cc,v 1.374 2003/04/25 22:32:21 robertc Exp $ + * $Id: main.cc,v 1.375 2003/04/27 00:18:01 hno Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -99,15 +99,27 @@ static void usage(void) { fprintf(stderr, +#if USE_WIN32_SERVICE + "Usage: %s [-dhirsvzCDFNRVYX] [-f config-file] [-[au] port] [-k signal] [-n name] [-O CommandLine]\n" +#else "Usage: %s [-dhsvzCDFNRVYX] [-f config-file] [-[au] port] [-k signal]\n" +#endif " -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" " %s\n" " -h Print help message.\n" +#if USE_WIN32_SERVICE + " -i Installs as a Windows Service (see -n option).\n" +#endif " -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" +#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 Enable logging to syslog.\n" " -u port Specify ICP port number (default: %d), disable with 0.\n" " -v Print version.\n" @@ -116,6 +128,10 @@ usage(void) " -D Disable initial DNS tests.\n" " -F Don't serve any requests until store is rebuilt.\n" " -N No daemon mode.\n" +#if USE_WIN32_SERVICE + " -O options\n" + " Set Windows Service Command line options in Registry.\n" +#endif " -R Do not set REUSEADDR on port.\n" " -S Double-check swap during rebuild.\n" " -V Virtual host httpd-accelerator.\n" @@ -131,7 +147,14 @@ mainParseOptions(int argc, char *argv[]) extern char *optarg; int c; +#if USE_WIN32_SERVICE + + while ((c = getopt(argc, argv, "CDFNO:RSVYXa:d:f:hik:m::n:rsu:vz?")) != -1) { +#else + while ((c = getopt(argc, argv, "CDFNRSVYXa:d:f:hk:m::su:vz?")) != -1) { +#endif + switch (c) { case 'C': @@ -149,6 +172,13 @@ mainParseOptions(int argc, char *argv[]) case 'N': opt_no_daemon = 1; break; +#if USE_WIN32_SERVICE + + case 'O': + opt_command_line = 1; + WIN32_Command_Line = xstrdup(optarg); + break; +#endif case 'R': opt_reuseaddr = 0; @@ -186,6 +216,15 @@ mainParseOptions(int argc, char *argv[]) break; +#if USE_WIN32_SERVICE + + case 'i': + opt_install_service = TRUE; + + break; + +#endif + case 'a': add_http_port(optarg); @@ -273,14 +312,35 @@ mainParseOptions(int argc, char *argv[]) } +#if USE_WIN32_SERVICE + + case 'n': + xfree(WIN32_Service_name); + + WIN32_Service_name = xstrdup(optarg); + + opt_signal_service = TRUE; + + break; + + case 'r': + opt_remove_service = TRUE; + + break; + +#endif + case 's': #if HAVE_SYSLOG opt_syslog_enable = 1; + break; + #else fatal("Logging to syslog not available on this platform"); + /* NOTREACHED */ #endif @@ -322,8 +382,7 @@ mainParseOptions(int argc, char *argv[]) /* ARGSUSED */ void -rotate_logs(int sig) -{ +rotate_logs(int sig) { do_rotate = 1; #ifndef _SQUID_MSWIN_ #if !HAVE_SIGACTION @@ -335,8 +394,7 @@ rotate_logs(int sig) /* ARGSUSED */ void -reconfigure(int sig) -{ +reconfigure(int sig) { do_reconfigure = 1; #ifndef _SQUID_MSWIN_ #if !HAVE_SIGACTION @@ -347,8 +405,7 @@ reconfigure(int sig) } void -shut_down(int sig) -{ +shut_down(int sig) { do_shutdown = sig == SIGINT ? -1 : 1; #ifndef _SQUID_MSWIN_ #ifdef KILL_PARENT_OPT @@ -371,8 +428,7 @@ shut_down(int sig) } static void -serverConnectionsOpen(void) -{ +serverConnectionsOpen(void) { clientOpenListenSockets(); icpConnectionsOpen(); #if USE_HTCP @@ -401,8 +457,7 @@ serverConnectionsOpen(void) } void -serverConnectionsClose(void) -{ +serverConnectionsClose(void) { assert(shutting_down || reconfiguring); clientHttpConnectionsClose(); icpConnectionShutdown(); @@ -425,8 +480,7 @@ serverConnectionsClose(void) } static void -mainReconfigure(void) -{ +mainReconfigure(void) { debug(1, 1) ("Restarting Squid Cache (version %s)...\n", version_string); reconfiguring = 1; /* Already called serverConnectionsClose and ipcacheShutdownServers() */ @@ -492,8 +546,7 @@ mainReconfigure(void) } static void -mainRotate(void) -{ +mainRotate(void) { icmpClose(); #if USE_DNSSERVERS @@ -526,8 +579,7 @@ mainRotate(void) } static void -setEffectiveUser(void) -{ +setEffectiveUser(void) { leave_suid(); /* Run as non privilegied user */ #ifdef _SQUID_OS2_ @@ -544,8 +596,7 @@ setEffectiveUser(void) } static void -mainSetCwd(void) -{ +mainSetCwd(void) { char pathbuf[MAXPATHLEN]; if (Config.coredump_dir) { @@ -572,8 +623,7 @@ mainSetCwd(void) #endif static void -mainInitialize(void) -{ +mainInitialize(void) { /* chroot if configured to run inside chroot */ if (Config.chroot_dir && chroot(Config.chroot_dir)) { @@ -774,326 +824,326 @@ extern "C" void WINAPI #else int main(int argc, char **argv) -#endif -{ +#endif { + int errcount = 0; - int n; /* # of GC'd objects */ - mode_t oldmask; +int n; /* # of GC'd objects */ +mode_t oldmask; #if HAVE_SBRK - sbrk_start = sbrk(0); +sbrk_start = sbrk(0); #endif - debug_log = stderr; +debug_log = stderr; - if (FD_SETSIZE < Squid_MaxFD) - Squid_MaxFD = FD_SETSIZE; +if (FD_SETSIZE < Squid_MaxFD) + Squid_MaxFD = FD_SETSIZE; #ifdef _SQUID_WIN32_ #ifdef USE_WIN32_SERVICE - if (WIN32_Subsystem_Init(&argc, &argv)) - return; +if (WIN32_Subsystem_Init(&argc, &argv)) + return; #else - { - int WIN32_init_err; +{ + int WIN32_init_err; - if ((WIN32_init_err = WIN32_Subsystem_Init())) - return WIN32_init_err; - } + if ((WIN32_init_err = WIN32_Subsystem_Init())) + return WIN32_init_err; +} #endif #endif - /* call mallopt() before anything else */ +/* call mallopt() before anything else */ #if HAVE_MALLOPT #ifdef M_GRAIN - /* Round up all sizes to a multiple of this */ - mallopt(M_GRAIN, 16); +/* Round up all sizes to a multiple of this */ +mallopt(M_GRAIN, 16); #endif #ifdef M_MXFAST - /* biggest size that is considered a small block */ - mallopt(M_MXFAST, 256); +/* biggest size that is considered a small block */ +mallopt(M_MXFAST, 256); #endif #ifdef M_NBLKS - /* allocate this many small blocks at once */ - mallopt(M_NLBLKS, 32); +/* allocate this many small blocks at once */ +mallopt(M_NLBLKS, 32); #endif #endif /* HAVE_MALLOPT */ - /* - * The plan here is to set the umask to 007 (deny others for - * read,write,execute), but only if the umask is not already - * set. Unfortunately, there is no way to get the current - * umask value without setting it. - */ - oldmask = umask(S_IRWXO); +/* + * The plan here is to set the umask to 007 (deny others for + * read,write,execute), but only if the umask is not already + * set. Unfortunately, there is no way to get the current + * umask value without setting it. + */ +oldmask = umask(S_IRWXO); - if (oldmask) - umask(oldmask); +if (oldmask) + umask(oldmask); - memset(&local_addr, '\0', sizeof(struct in_addr)); +memset(&local_addr, '\0', sizeof(struct in_addr)); - safe_inet_addr(localhost, &local_addr); +safe_inet_addr(localhost, &local_addr); - memset(&any_addr, '\0', sizeof(struct in_addr)); +memset(&any_addr, '\0', sizeof(struct in_addr)); - safe_inet_addr("0.0.0.0", &any_addr); +safe_inet_addr("0.0.0.0", &any_addr); - memset(&no_addr, '\0', sizeof(struct in_addr)); +memset(&no_addr, '\0', sizeof(struct in_addr)); - safe_inet_addr("255.255.255.255", &no_addr); +safe_inet_addr("255.255.255.255", &no_addr); - squid_srandom(time(NULL)); +squid_srandom(time(NULL)); - getCurrentTime(); +getCurrentTime(); - squid_start = current_time; +squid_start = current_time; - failure_notify = fatal_dump; +failure_notify = fatal_dump; #if USE_WIN32_SERVICE - WIN32_svcstatusupdate(SERVICE_START_PENDING, 10000); +WIN32_svcstatusupdate(SERVICE_START_PENDING, 10000); #endif - mainParseOptions(argc, argv); +mainParseOptions(argc, argv); #if USE_WIN32_SERVICE - if (opt_install_service) { - WIN32_InstallService(); - return; - } +if (opt_install_service) { + WIN32_InstallService(); + return; +} - if (opt_remove_service) { - WIN32_RemoveService(); - return; - } +if (opt_remove_service) { + WIN32_RemoveService(); + return; +} - if (opt_command_line) { - WIN32_SetServiceCommandLine(); - return; - } +if (opt_command_line) { + WIN32_SetServiceCommandLine(); + return; +} #endif - /* parse configuration file - * note: in "normal" case this used to be called from mainInitialize() */ - { - int parse_err; +/* parse configuration file + * note: in "normal" case this used to be called from mainInitialize() */ +{ + int parse_err; - if (!ConfigFile) - ConfigFile = xstrdup(DefaultConfigFile); + if (!ConfigFile) + ConfigFile = xstrdup(DefaultConfigFile); - assert(!configured_once); + assert(!configured_once); #if USE_LEAKFINDER - leakInit(); + leakInit(); #endif - Mem::Init(); + Mem::Init(); - cbdataInit(); + cbdataInit(); - eventInit(); /* eventInit() is required for config parsing */ + eventInit(); /* eventInit() is required for config parsing */ - storeFsInit(); /* required for config parsing */ + storeFsInit(); /* required for config parsing */ - authenticateSchemeInit(); /* required for config parsign */ + authenticateSchemeInit(); /* required for config parsign */ - parse_err = parseConfigFile(ConfigFile); + parse_err = parseConfigFile(ConfigFile); - if (opt_parse_cfg_only) + if (opt_parse_cfg_only) #if USE_WIN32_SERVICE - return; + return; #else - return parse_err; + return parse_err; #endif - } - if (-1 == opt_send_signal) - if (checkRunningPid()) - exit(1); +} +if (-1 == opt_send_signal) + if (checkRunningPid()) + exit(1); #if TEST_ACCESS - comm_init(); +comm_init(); - comm_select_init(); +comm_select_init(); - mainInitialize(); +mainInitialize(); - test_access(); +test_access(); - return 0; +return 0; #endif - /* send signal to running copy and exit */ - if (opt_send_signal != -1) { - /* chroot if configured to run inside chroot */ - - if (Config.chroot_dir && chroot(Config.chroot_dir)) { - fatal("failed to chroot"); - } +/* send signal to running copy and exit */ +if (opt_send_signal != -1) { + /* chroot if configured to run inside chroot */ - sendSignal(); - /* NOTREACHED */ + if (Config.chroot_dir && chroot(Config.chroot_dir)) { + fatal("failed to chroot"); } - if (opt_create_swap_dirs) { - /* chroot if configured to run inside chroot */ + sendSignal(); + /* NOTREACHED */ +} - if (Config.chroot_dir && chroot(Config.chroot_dir)) { - fatal("failed to chroot"); - } +if (opt_create_swap_dirs) { + /* chroot if configured to run inside chroot */ + + if (Config.chroot_dir && chroot(Config.chroot_dir)) { + fatal("failed to chroot"); + } - setEffectiveUser(); - debug(0, 0) ("Creating Swap Directories\n"); - storeCreateSwapDirectories(); + setEffectiveUser(); + debug(0, 0) ("Creating Swap Directories\n"); + storeCreateSwapDirectories(); #if USE_WIN32_SERVICE - return; + return; #else - return 0; + return 0; #endif - } +} - if (!opt_no_daemon) - watch_child(argv); +if (!opt_no_daemon) + watch_child(argv); - setMaxFD(); +setMaxFD(); - if (opt_catch_signals) - for (n = Squid_MaxFD; n > 2; n--) - close(n); +if (opt_catch_signals) + for (n = Squid_MaxFD; n > 2; n--) + close(n); - /* init comm module */ - comm_init(); +/* init comm module */ +comm_init(); - comm_select_init(); +comm_select_init(); - if (opt_no_daemon) { - /* we have to init fdstat here. */ - fd_open(0, FD_LOG, "stdin"); - fd_open(1, FD_LOG, "stdout"); - fd_open(2, FD_LOG, "stderr"); - } +if (opt_no_daemon) { + /* we have to init fdstat here. */ + fd_open(0, FD_LOG, "stdin"); + fd_open(1, FD_LOG, "stdout"); + fd_open(2, FD_LOG, "stderr"); +} #if USE_WIN32_SERVICE - WIN32_svcstatusupdate(SERVICE_START_PENDING, 10000); +WIN32_svcstatusupdate(SERVICE_START_PENDING, 10000); #endif - mainInitialize(); +mainInitialize(); #if USE_WIN32_SERVICE - WIN32_svcstatusupdate(SERVICE_RUNNING, 0); +WIN32_svcstatusupdate(SERVICE_RUNNING, 0); #endif - /* main loop */ +/* main loop */ - for (;;) { - if (do_reconfigure) { - mainReconfigure(); - do_reconfigure = 0; - } else if (do_rotate) { - mainRotate(); - do_rotate = 0; - } else if (do_shutdown) { - time_t wait = do_shutdown > 0 ? (int) Config.shutdownLifetime : 0; - debug(1, 1) ("Preparing for shutdown after %d requests\n", - statCounter.client_http.requests); - debug(1, 1) ("Waiting %d seconds for active connections to finish\n", - (int) wait); - do_shutdown = 0; - shutting_down = 1; +for (;;) { + if (do_reconfigure) { + mainReconfigure(); + do_reconfigure = 0; + } else if (do_rotate) { + mainRotate(); + do_rotate = 0; + } else if (do_shutdown) { + time_t wait = do_shutdown > 0 ? (int) Config.shutdownLifetime : 0; + debug(1, 1) ("Preparing for shutdown after %d requests\n", + statCounter.client_http.requests); + debug(1, 1) ("Waiting %d seconds for active connections to finish\n", + (int) wait); + do_shutdown = 0; + shutting_down = 1; #if USE_WIN32_SERVICE - WIN32_svcstatusupdate(SERVICE_STOP_PENDING, (wait + 1) * 1000); + WIN32_svcstatusupdate(SERVICE_STOP_PENDING, (wait + 1) * 1000); #endif - serverConnectionsClose(); + serverConnectionsClose(); #if USE_DNSSERVERS - dnsShutdown(); + dnsShutdown(); #else - idnsShutdown(); + idnsShutdown(); #endif - redirectShutdown(); - externalAclShutdown(); - eventAdd("SquidShutdown", SquidShutdown, NULL, (double) (wait + 1), 1); - } + redirectShutdown(); + externalAclShutdown(); + eventAdd("SquidShutdown", SquidShutdown, NULL, (double) (wait + 1), 1); + } - eventRun(); - int loop_delay = eventNextTime(); + eventRun(); + int loop_delay = eventNextTime(); - if (loop_delay < 0) - loop_delay = 0; + if (loop_delay < 0) + loop_delay = 0; - /* Attempt any pending storedir IO */ - storeDirCallback(); + /* Attempt any pending storedir IO */ + storeDirCallback(); - comm_calliocallback(); + comm_calliocallback(); - switch (comm_select(loop_delay)) { + switch (comm_select(loop_delay)) { - case COMM_OK: - errcount = 0; /* reset if successful */ - break; + case COMM_OK: + errcount = 0; /* reset if successful */ + break; - case COMM_ERROR: - errcount++; - debug(1, 0) ("Select loop Error. Retry %d\n", errcount); + case COMM_ERROR: + errcount++; + debug(1, 0) ("Select loop Error. Retry %d\n", errcount); - if (errcount == 10) - fatal_dump("Select Loop failed!"); + if (errcount == 10) + fatal_dump("Select Loop failed!"); - break; + break; - case COMM_TIMEOUT: - break; + case COMM_TIMEOUT: + break; - case COMM_SHUTDOWN: - SquidShutdown(NULL); + case COMM_SHUTDOWN: + SquidShutdown(NULL); - break; + break; - default: - fatal_dump("MAIN: Internal error -- this should never happen."); + default: + fatal_dump("MAIN: Internal error -- this should never happen."); - break; - } + break; } +} - /* NOTREACHED */ +/* NOTREACHED */ #if USE_WIN32_SERVICE - return; +return; #else - return 0; +return 0; #endif }