当前位置: 技术问答>linux和unix
编程问题
来源: 互联网 发布时间:2014-11-19
本文导语: mainInitialize(void) { static int first_time = 1; if (opt_catch_signals) { squid_signal(SIGSEGV, death, SA_NODEFER | SA_RESETHAND); squid_signal(SIGBUS, death, SA_NODEFER | SA_RESETHAND); } squid_signal(SIGPIPE, SIG_IGN, ...
mainInitialize(void)
{
static int first_time = 1;
if (opt_catch_signals) {
squid_signal(SIGSEGV, death, SA_NODEFER | SA_RESETHAND);
squid_signal(SIGBUS, death, SA_NODEFER | SA_RESETHAND);
}
squid_signal(SIGPIPE, SIG_IGN, SA_RESTART);
squid_signal(SIGCHLD, sig_child, SA_NODEFER | SA_RESTART);
if (ConfigFile == NULL)
ConfigFile = xstrdup(DefaultConfigFile);
parseConfigFile(ConfigFile);
setEffectiveUser();
if (httpPortNumOverride != 1)
Config.Port.http = (u_short) httpPortNumOverride;
if (icpPortNumOverride != 1)
Config.Port.icp = (u_short) icpPortNumOverride;
_db_init(Config.Log.log, Config.debugOptions);
fdstat_open(fileno(debug_log), FD_LOG);
fd_note(fileno(debug_log), Config.Log.log);
debug(1, 0, "Starting Squid Cache version %s for %s...n",
version_string,
CONFIG_HOST_TYPE);
debug(1, 1, "With %d file descriptors availablen", Squid_MaxFD);
if (first_time) {
stmemInit(); /* stmem must go before at least redirect */
disk_init(); /* disk_init must go before ipcache_init() */
}
ipcache_init();
fqdncache_init();
dnsOpenServers();
redirectOpenServers();
useragentOpenLog();
#if 0 /* USE_V6_LOCALHOST */
ftpInitialize6();
#endif
ftpInitialize();
#if MALLOC_DBG
malloc_debug(0, malloc_debug_level);
#endif
if (first_time) {
unlinkdInit();
/* module initialization */
urlInitialize();
stat_init(&HTTPCacheInfo, Config.Log.access);
stat_init(&ICPCacheInfo, NULL);
storeInit();
#if FORW_VIA_LOG
icpInit(0);
#endif
if (Config.effectiveUser) {
/* we were probably started as root, so cd to a swap
* directory in case we dump core */
if (chdir(swappath(0)) = 0 && (!httpd_accel_mode || Config.Accel.withProxy))
neighbors_open(theOutIcpConnection);
if (first_time)
writePidFile(); /* write PID file */
squid_signal(SIGUSR1, rotate_logs, SA_RESTART);
squid_signal(SIGUSR2, sigusr2_handle, SA_RESTART);
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);
debug(1, 0, "Ready to serve requests.n");
if (first_time) {
eventAdd("storePurgeOld", storePurgeOld, NULL, Config.cleanRate);
eventAdd("storeMaintain", storeMaintainSwapSpace, NULL, 1);
eventAdd("storeDirClean", storeDirClean, NULL, 15);
if (Config.Announce.on)
eventAdd("start_announce", start_announce, NULL, 3600);
eventAdd("ipcache_purgelru", (EVH) ipcache_purgelru, NULL, 10);
}
first_time = 0;
}
void
有太多不懂的地方了,请各位大霞给看看,整段程序是什么意思,还有细节的部分也讲讲,比如0,1,-1是什么作用
{
static int first_time = 1;
if (opt_catch_signals) {
squid_signal(SIGSEGV, death, SA_NODEFER | SA_RESETHAND);
squid_signal(SIGBUS, death, SA_NODEFER | SA_RESETHAND);
}
squid_signal(SIGPIPE, SIG_IGN, SA_RESTART);
squid_signal(SIGCHLD, sig_child, SA_NODEFER | SA_RESTART);
if (ConfigFile == NULL)
ConfigFile = xstrdup(DefaultConfigFile);
parseConfigFile(ConfigFile);
setEffectiveUser();
if (httpPortNumOverride != 1)
Config.Port.http = (u_short) httpPortNumOverride;
if (icpPortNumOverride != 1)
Config.Port.icp = (u_short) icpPortNumOverride;
_db_init(Config.Log.log, Config.debugOptions);
fdstat_open(fileno(debug_log), FD_LOG);
fd_note(fileno(debug_log), Config.Log.log);
debug(1, 0, "Starting Squid Cache version %s for %s...n",
version_string,
CONFIG_HOST_TYPE);
debug(1, 1, "With %d file descriptors availablen", Squid_MaxFD);
if (first_time) {
stmemInit(); /* stmem must go before at least redirect */
disk_init(); /* disk_init must go before ipcache_init() */
}
ipcache_init();
fqdncache_init();
dnsOpenServers();
redirectOpenServers();
useragentOpenLog();
#if 0 /* USE_V6_LOCALHOST */
ftpInitialize6();
#endif
ftpInitialize();
#if MALLOC_DBG
malloc_debug(0, malloc_debug_level);
#endif
if (first_time) {
unlinkdInit();
/* module initialization */
urlInitialize();
stat_init(&HTTPCacheInfo, Config.Log.access);
stat_init(&ICPCacheInfo, NULL);
storeInit();
#if FORW_VIA_LOG
icpInit(0);
#endif
if (Config.effectiveUser) {
/* we were probably started as root, so cd to a swap
* directory in case we dump core */
if (chdir(swappath(0)) = 0 && (!httpd_accel_mode || Config.Accel.withProxy))
neighbors_open(theOutIcpConnection);
if (first_time)
writePidFile(); /* write PID file */
squid_signal(SIGUSR1, rotate_logs, SA_RESTART);
squid_signal(SIGUSR2, sigusr2_handle, SA_RESTART);
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);
debug(1, 0, "Ready to serve requests.n");
if (first_time) {
eventAdd("storePurgeOld", storePurgeOld, NULL, Config.cleanRate);
eventAdd("storeMaintain", storeMaintainSwapSpace, NULL, 1);
eventAdd("storeDirClean", storeDirClean, NULL, 15);
if (Config.Announce.on)
eventAdd("start_announce", start_announce, NULL, 3600);
eventAdd("ipcache_purgelru", (EVH) ipcache_purgelru, NULL, 10);
}
first_time = 0;
}
void
有太多不懂的地方了,请各位大霞给看看,整段程序是什么意思,还有细节的部分也讲讲,比如0,1,-1是什么作用
|
怎么看起来像是squid的源程序?只能大概说一些:
mainInitialize(void)
{
/*第一次标志*/
static int first_time = 1;
/*处理溢出信号*/
if (opt_catch_signals) {
squid_signal(SIGSEGV, death, SA_NODEFER | SA_RESETHAND);
squid_signal(SIGBUS, death, SA_NODEFER | SA_RESETHAND);
}
/*忽略管道信号*/
squid_signal(SIGPIPE, SIG_IGN, SA_RESTART);
/*接受子进程信号*/
squid_signal(SIGCHLD, sig_child, SA_NODEFER | SA_RESTART);
/*判断是否有配置文件,如果有的话,打开并解析*/
if (ConfigFile == NULL)
ConfigFile = xstrdup(DefaultConfigFile);
parseConfigFile(ConfigFile);
/*猜想是设置有效的用户*/
setEffectiveUser();
/*重用端口?*/
if (httpPortNumOverride != 1)
Config.Port.http = (u_short) httpPortNumOverride;
if (icpPortNumOverride != 1)
Config.Port.icp = (u_short) icpPortNumOverride;
/*初始化debug文件,并记录一些debug信息*/
_db_init(Config.Log.log, Config.debugOptions);
fdstat_open(fileno(debug_log), FD_LOG);
fd_note(fileno(debug_log), Config.Log.log);
debug(1, 0, "Starting Squid Cache version %s for %s...n",
version_string,
CONFIG_HOST_TYPE);
debug(1, 1, "With %d file descriptors availablen", Squid_MaxFD);
/*如果是首次启动初始化内存?和硬盘空间*/
if (first_time) {
stmemInit(); /* stmem must go before at least redirect */
disk_init(); /* disk_init must go before ipcache_init() */
}
/*启动一些进程并连接DNS服务器 重定向服务,并初始化用户的log*/
ipcache_init();
fqdncache_init();
dnsOpenServers();
redirectOpenServers();
useragentOpenLog();
/*是否用ipv6*/
#if 0 /* USE_V6_LOCALHOST */
ftpInitialize6();
#endif
ftpInitialize();
#if MALLOC_DBG
malloc_debug(0, malloc_debug_level);
#endif
/*如果第一次启动初始化*/
if (first_time) {
unlinkdInit();
/* module initialization */
urlInitialize();
stat_init(&HTTPCacheInfo, Config.Log.access);
stat_init(&ICPCacheInfo, NULL);
storeInit();
#if FORW_VIA_LOG
icpInit(0);
#endif
/*将coredown后的内存映像转存到/目录下*/
if (Config.effectiveUser) {
/* we were probably started as root, so cd to a swap
* directory in case we dump core */
if (chdir(swappath(0)) = 0 && (!httpd_accel_mode || Config.Accel.withProxy))
neighbors_open(theOutIcpConnection);
/*将进程ID写到对应的pid文件中*/
if (first_time)
writePidFile(); /* write PID file */
squid_signal(SIGUSR1, rotate_logs, SA_RESTART);
squid_signal(SIGUSR2, sigusr2_handle, SA_RESTART);
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);
debug(1, 0, "Ready to serve requests.n");
/*添加一些事件处理函数*/
if (first_time) {
eventAdd("storePurgeOld", storePurgeOld, NULL, Config.cleanRate);
eventAdd("storeMaintain", storeMaintainSwapSpace, NULL, 1);
eventAdd("storeDirClean", storeDirClean, NULL, 15);
if (Config.Announce.on)
eventAdd("start_announce", start_announce, NULL, 3600);
eventAdd("ipcache_purgelru", (EVH) ipcache_purgelru, NULL, 10);
}
first_time = 0;
}
mainInitialize(void)
{
/*第一次标志*/
static int first_time = 1;
/*处理溢出信号*/
if (opt_catch_signals) {
squid_signal(SIGSEGV, death, SA_NODEFER | SA_RESETHAND);
squid_signal(SIGBUS, death, SA_NODEFER | SA_RESETHAND);
}
/*忽略管道信号*/
squid_signal(SIGPIPE, SIG_IGN, SA_RESTART);
/*接受子进程信号*/
squid_signal(SIGCHLD, sig_child, SA_NODEFER | SA_RESTART);
/*判断是否有配置文件,如果有的话,打开并解析*/
if (ConfigFile == NULL)
ConfigFile = xstrdup(DefaultConfigFile);
parseConfigFile(ConfigFile);
/*猜想是设置有效的用户*/
setEffectiveUser();
/*重用端口?*/
if (httpPortNumOverride != 1)
Config.Port.http = (u_short) httpPortNumOverride;
if (icpPortNumOverride != 1)
Config.Port.icp = (u_short) icpPortNumOverride;
/*初始化debug文件,并记录一些debug信息*/
_db_init(Config.Log.log, Config.debugOptions);
fdstat_open(fileno(debug_log), FD_LOG);
fd_note(fileno(debug_log), Config.Log.log);
debug(1, 0, "Starting Squid Cache version %s for %s...n",
version_string,
CONFIG_HOST_TYPE);
debug(1, 1, "With %d file descriptors availablen", Squid_MaxFD);
/*如果是首次启动初始化内存?和硬盘空间*/
if (first_time) {
stmemInit(); /* stmem must go before at least redirect */
disk_init(); /* disk_init must go before ipcache_init() */
}
/*启动一些进程并连接DNS服务器 重定向服务,并初始化用户的log*/
ipcache_init();
fqdncache_init();
dnsOpenServers();
redirectOpenServers();
useragentOpenLog();
/*是否用ipv6*/
#if 0 /* USE_V6_LOCALHOST */
ftpInitialize6();
#endif
ftpInitialize();
#if MALLOC_DBG
malloc_debug(0, malloc_debug_level);
#endif
/*如果第一次启动初始化*/
if (first_time) {
unlinkdInit();
/* module initialization */
urlInitialize();
stat_init(&HTTPCacheInfo, Config.Log.access);
stat_init(&ICPCacheInfo, NULL);
storeInit();
#if FORW_VIA_LOG
icpInit(0);
#endif
/*将coredown后的内存映像转存到/目录下*/
if (Config.effectiveUser) {
/* we were probably started as root, so cd to a swap
* directory in case we dump core */
if (chdir(swappath(0)) = 0 && (!httpd_accel_mode || Config.Accel.withProxy))
neighbors_open(theOutIcpConnection);
/*将进程ID写到对应的pid文件中*/
if (first_time)
writePidFile(); /* write PID file */
squid_signal(SIGUSR1, rotate_logs, SA_RESTART);
squid_signal(SIGUSR2, sigusr2_handle, SA_RESTART);
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);
debug(1, 0, "Ready to serve requests.n");
/*添加一些事件处理函数*/
if (first_time) {
eventAdd("storePurgeOld", storePurgeOld, NULL, Config.cleanRate);
eventAdd("storeMaintain", storeMaintainSwapSpace, NULL, 1);
eventAdd("storeDirClean", storeDirClean, NULL, 15);
if (Config.Announce.on)
eventAdd("start_announce", start_announce, NULL, 3600);
eventAdd("ipcache_purgelru", (EVH) ipcache_purgelru, NULL, 10);
}
first_time = 0;
}