⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 -
💻 C
📖 第 1 页 / 共 2 页
字号:
    setEffectiveUser();    assert(Config.Port.http);    if (httpPortNumOverride != 1)	Config.Port.http->i = (u_short) httpPortNumOverride;    if (icpPortNumOverride != 1)	Config.Port.icp = (u_short) icpPortNumOverride;    _db_init(Config.Log.log, Config.debugOptions);    fd_open(fileno(debug_log), FD_LOG, Config.Log.log);#if MEM_GEN_TRACE    log_trace_init("/tmp/squid.alloc");#endif    debug(1, 0) ("Starting Squid Cache version %s for %s...\n",	version_string,	CONFIG_HOST_TYPE);    debug(1, 1) ("Process ID %d\n", (int) getpid());    debug(1, 1) ("With %d file descriptors available\n", Squid_MaxFD);    if (!configured_once)	disk_init();		/* disk_init must go before ipcache_init() */    ipcache_init();    fqdncache_init();    dnsInit();    redirectInit();    authenticateInit();    useragentOpenLog();    httpHeaderInitModule();	/* must go before any header processing (e.g. the one in errorInitialize) */    httpReplyInitModule();	/* must go before accepting replies */    errorInitialize();    accessLogInit();#if USE_IDENT    identInit();#endif#ifdef SQUID_SNMP    snmpInit();#endif#if MALLOC_DBG    malloc_debug(0, malloc_debug_level);#endif    if (!configured_once) {	unlinkdInit();	urlInitialize();	cachemgrInit();	statInit();	storeInit();	mainSetCwd();	/* after this point we want to see the mallinfo() output */	do_mallinfo = 1;	mimeInit(Config.mimeTablePathname);	pconnInit();	eventInit();	refreshInit();#if DELAY_POOLS	delayPoolsInit();#endif	fwdInit();    }    serverConnectionsOpen();    if (theOutIcpConnection >= 0) {	if (!Config2.Accel.on || Config.onoff.accel_with_proxy)	    neighbors_open(theOutIcpConnection);	else	    debug(1, 1) ("ICP port disabled in httpd_accelerator mode\n");    }    if (!configured_once)	writePidFile();		/* write PID file */#ifdef _SQUID_LINUX_THREADS_    squid_signal(SIGQUIT, rotate_logs, SA_RESTART);    squid_signal(SIGTRAP, sigusr2_handle, SA_RESTART);#else    squid_signal(SIGUSR1, rotate_logs, SA_RESTART);    squid_signal(SIGUSR2, sigusr2_handle, SA_RESTART);#endif    squid_signal(SIGHUP, reconfigure, SA_RESTART);    squid_signal(SIGTERM, shut_down, SA_NODEFER | SA_RESETHAND | SA_RESTART);    squid_signal(SIGINT, shut_down, SA_NODEFER | SA_RESETHAND | SA_RESTART);#if ALARM_UPDATES_TIME    squid_signal(SIGALRM, time_tick, SA_RESTART);    alarm(1);#endif    debug(1, 1) ("Ready to serve requests.\n");    if (!configured_once) {	eventAdd("storeMaintain", storeMaintainSwapSpace, NULL, 1.0, 1);	eventAdd("storeDirClean", storeDirClean, NULL, 15.0, 1);	if (Config.onoff.announce)	    eventAdd("start_announce", start_announce, NULL, 3600.0, 1);	eventAdd("ipcache_purgelru", ipcache_purgelru, NULL, 10.0, 1);	eventAdd("fqdncache_purgelru", fqdncache_purgelru, NULL, 15.0, 1);    }    configured_once = 1;}intmain(int argc, char **argv){    int errcount = 0;    int n;			/* # of GC'd objects */    time_t loop_delay;    debug_log = stderr;    if (FD_SETSIZE < Squid_MaxFD)	Squid_MaxFD = FD_SETSIZE;    /* call mallopt() before anything else */#if HAVE_MALLOPT#ifdef M_GRAIN    /* 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);#endif#ifdef M_NBLKS    /* allocate this many small blocks at once */    mallopt(M_NLBLKS, 32);#endif#endif /* HAVE_MALLOPT */    memset(&local_addr, '\0', sizeof(struct in_addr));    safe_inet_addr(localhost, &local_addr);    memset(&any_addr, '\0', sizeof(struct in_addr));    safe_inet_addr("0.0.0.0", &any_addr);    memset(&no_addr, '\0', sizeof(struct in_addr));    safe_inet_addr("255.255.255.255", &no_addr);    squid_srandom(time(NULL));    getCurrentTime();    squid_start = current_time;    failure_notify = fatal_dump;    mainParseOptions(argc, argv);    /* parse configuration file     * note: in "normal" case this used to be called from mainInitialize() */    {	int parse_err;	if (!ConfigFile)	    ConfigFile = xstrdup(DefaultConfigFile);	assert(!configured_once);	cbdataInit();#if USE_LEAKFINDER	leakInit();#endif	memInit();		/* memInit is required for config parsing */	parse_err = parseConfigFile(ConfigFile);	if (opt_parse_cfg_only)	    return parse_err;    }    /* send signal to running copy and exit */    if (opt_send_signal != -1) {	sendSignal();	/* NOTREACHED */    }    if (opt_create_swap_dirs) {	setEffectiveUser();	debug(0, 0) ("Creating Swap Directories\n");	storeCreateSwapDirectories();	return 0;    }    if (!opt_no_daemon)	watch_child(argv);    setMaxFD();    if (opt_catch_signals)	for (n = Squid_MaxFD; n > 2; n--)	    close(n);    /* init comm module */    comm_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");    }    mainInitialize();    /* 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",		Counter.client_http.requests);	    debug(1, 1) ("Waiting %d seconds for active connections to finish\n",		wait);	    do_shutdown = 0;	    shutting_down = 1;	    serverConnectionsClose();	    dnsShutdown();	    redirectShutdown();	    authenticateShutdown();	    eventAdd("SquidShutdown", SquidShutdown, NULL, (double) (wait + 1), 1);	}	eventRun();	if ((loop_delay = eventNextTime()) < 0)	    loop_delay = 0;#if HAVE_POLL	switch (comm_poll(loop_delay)) {#else	switch (comm_select(loop_delay)) {#endif	case COMM_OK:	    errcount = 0;	/* reset if successful */	    break;	case COMM_ERROR:	    errcount++;	    debug(1, 0) ("Select loop Error. Retry %d\n", errcount);	    if (errcount == 10)		fatal_dump("Select Loop failed!");	    break;	case COMM_TIMEOUT:	    break;	case COMM_SHUTDOWN:	    SquidShutdown(NULL);	    break;	default:	    fatal_dump("MAIN: Internal error -- this should never happen.");	    break;	}    }    /* NOTREACHED */    return 0;}static voidsendSignal(void){    pid_t pid;    debug_log = stderr;    pid = readPidFile();    if (pid > 1) {	if (kill(pid, opt_send_signal) &&	/* ignore permissions if just running check */	    !(opt_send_signal == 0 && errno == EPERM)) {	    fprintf(stderr, "%s: ERROR: Could not send ", appname);	    fprintf(stderr, "signal %d to process %d: %s\n",		opt_send_signal, (int) pid, xstrerror());	    exit(1);	}    } else {	fprintf(stderr, "%s: ERROR: No running copy\n", appname);	exit(1);    }    /* signal successfully sent */    exit(0);}static voidwatch_child(char *argv[]){    char *prog;    int failcount = 0;    time_t start;    time_t stop;#ifdef _SQUID_NEXT_    union wait status;#else    int status;#endif    pid_t pid;    int i;    if (*(argv[0]) == '(')	return;    openlog(appname, LOG_PID | LOG_NDELAY | LOG_CONS, LOG_LOCAL4);    if ((pid = fork()) < 0)	syslog(LOG_ALERT, "fork failed: %s", xstrerror());    else if (pid > 0)	exit(0);    if (setsid() < 0)	syslog(LOG_ALERT, "setsid failed: %s", xstrerror());#ifdef TIOCNOTTY    if ((i = open("/dev/tty", O_RDWR)) >= 0) {	ioctl(i, TIOCNOTTY, NULL);	close(i);    }#endif    for (i = 0; i < Squid_MaxFD; i++)	close(i);#if NOT_NEEDED    umask(0);#endif    for (;;) {	if ((pid = fork()) == 0) {	    /* child */	    prog = xstrdup(argv[0]);	    argv[0] = xstrdup("(squid)");	    execvp(prog, argv);	    syslog(LOG_ALERT, "execvp failed: %s", xstrerror());	}	/* parent */	syslog(LOG_NOTICE, "Squid Parent: child process %d started", pid);	time(&start);	squid_signal(SIGINT, SIG_IGN, SA_RESTART);#ifdef _SQUID_NEXT_	pid = wait3(&status, 0, NULL);#else	pid = waitpid(-1, &status, 0);#endif	time(&stop);	if (WIFEXITED(status)) {	    syslog(LOG_NOTICE,		"Squid Parent: child process %d exited with status %d",		pid, WEXITSTATUS(status));	} else if (WIFSIGNALED(status)) {	    syslog(LOG_NOTICE,		"Squid Parent: child process %d exited due to signal %d",		pid, WTERMSIG(status));	} else {	    syslog(LOG_NOTICE, "Squid Parent: child process %d exited", pid);	}	if (stop - start < 10)	    failcount++;	else	    failcount = 0;	if (failcount == 5) {	    syslog(LOG_ALERT, "Exiting due to repeated, frequent failures");	    exit(1);	}	if (WIFEXITED(status))	    if (WEXITSTATUS(status) == 0)		exit(0);	squid_signal(SIGINT, SIG_DFL, SA_RESTART);	sleep(3);    }    /* NOTREACHED */}static voidSquidShutdown(void *unused){    debug(1, 1) ("Shutting down...\n");    if (Config.pidFilename && strcmp(Config.pidFilename, "none")) {	enter_suid();	safeunlink(Config.pidFilename, 0);	leave_suid();    }    icpConnectionClose();#if USE_HTCP    htcpSocketClose();#endif#ifdef SQUID_SNMP    snmpConnectionClose();#endif    releaseServerSockets();    commCloseAllSockets();    unlinkdClose();#if USE_ASYNC_IO    aioSync();			/* flush pending object writes / unlinks */#endif    storeDirWriteCleanLogs(0);    PrintRusage();    dumpMallocStats();#if USE_ASYNC_IO    aioSync();			/* flush log writes */#endif    storeLogClose();    accessLogClose();#if USE_ASYNC_IO    aioSync();			/* flush log close */#endif#if PURIFY || XMALLOC_TRACE    configFreeMemory();    storeFreeMemory();    /*stmemFreeMemory(); */    netdbFreeMemory();    ipcacheFreeMemory();    fqdncacheFreeMemory();    asnFreeMemory();    clientdbFreeMemory();    httpHeaderCleanModule();    statFreeMemory();    eventFreeMemory();    mimeFreeMemory();    errorClean();#endif#if !XMALLOC_TRACE    if (opt_no_daemon) {	file_close(0);	file_close(1);	file_close(2);    }#endif    fdDumpOpen();    fdFreeMemory();    memClean();#if XMALLOC_TRACE    xmalloc_find_leaks();    debug(1, 0) ("Memory used after shutdown: %d\n", xmalloc_total);#endif#if MEM_GEN_TRACE    log_trace_done();#endif    debug(1, 1) ("Squid Cache (Version %s): Exiting normally.\n",	version_string);    fclose(debug_log);    exit(0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -