简介
版本:thttpd-2.29
现象
在启动thttpd网页服务器后,如果更改本机时间(修改为过去的时间),thttpd会自动断开(实际上是调用了abort()函数)
原因
这是一段计时器,去定时清理没用到的计时器
/* Set up the occasional timer. */
if ( tmr_create( (struct timeval*) 0, occasional, JunkClientData, OCCASIONAL_TIME * 1000L, 1 ) == (Timer*) 0 )
{
syslog( LOG_CRIT, "tmr_create(occasional) failed" );
exit( 1 );
}
里面有一个回调函数occasional,负责清理并给看门狗喂狗
当时间被更改为过去时,会使程序不喂狗,导致程序以为连接已失效,调用abort()函数
解决方案
在更改时间后,重新调用tmr_create函数,重新计时
void restart_timer()
{
syslog( LOG_NOTICE, "restart thttpd timer" );
timer_restart_flag = 0;
tmr_term();
/* Set up the occasional timer. */
if ( tmr_create( (struct timeval*) 0, occasional, JunkClientData, OCCASIONAL_TIME * 1000L, 1 ) == (Timer*) 0 )
{
syslog( LOG_CRIT, "tmr_create(occasional) failed" );
exit( 1 );
}
/* Set up the idle timer. */
if ( tmr_create( (struct timeval*) 0, idle, JunkClientData, 5 * 1000L, 1 ) == (Timer*) 0 )
{
syslog( LOG_CRIT, "tmr_create(idle) failed" );
exit( 1 );
}
if ( numthrottles > 0 )
{
/* Set up the throttles timer. */
if ( tmr_create( (struct timeval*) 0, update_throttles, JunkClientData, THROTTLE_TIME * 1000L, 1 ) == (Timer*) 0 )
{
syslog( LOG_CRIT, "tmr_create(update_throttles) failed" );
exit( 1 );
}
}
#ifdef STATS_TIME
/* Set up the stats timer. */
if ( tmr_create( (struct timeval*) 0, show_stats, JunkClientData, STATS_TIME * 1000L, 1 ) == (Timer*) 0 )
{
syslog( LOG_CRIT, "tmr_create(show_stats) failed" );
exit( 1 );
}
#endif /* STATS_TIME */
}