thttpd更改时间后自动断开(aborted)

thttpd更改到过去的时间后自动断开(aborted)

简介

版本: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 */
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值