diff -urN asterisk-1.2.18.orig/channels/chan_agent.c asterisk-1.2.18/channels/chan_agent.c --- asterisk-1.2.18.orig/channels/chan_agent.c 2007-03-01 03:55:45.000000000 +0900 +++ asterisk-1.2.18/channels/chan_agent.c 2007-07-09 18:53:19.589923624 +0900 @@ -836,7 +836,7 @@ /* Not dead -- check availability now */ ast_mutex_lock(&p->lock); /* Store last disconnect time */ - p->lastdisc = ast_tvnow(); + p->lastdisc = ast_tvadd(ast_tvnow(), ast_samp2tv(p->wrapuptime, 1000)); ast_mutex_unlock(&p->lock); } /* Release ownership of the agent to other threads (presumably running the login app). */ @@ -856,7 +856,7 @@ ast_mutex_lock(&p->lock); res = p->app_sleep_cond; if (p->lastdisc.tv_sec) { - if (ast_tvdiff_ms(ast_tvnow(), p->lastdisc) > p->wrapuptime) + if (ast_tvdiff_ms(ast_tvnow(), p->lastdisc) > 0) res = 1; } ast_mutex_unlock(&p->lock); @@ -1314,7 +1314,8 @@ ast_strlen_zero(p->loginchan)) { if (p->chan) hasagent++; - if (!p->lastdisc.tv_sec) { + if (!p->lastdisc.tv_sec || (ast_tvnow().tv_sec > p->lastdisc.tv_sec)) { + p->lastdisc = ast_tv(0, 0); /* Agent must be registered, but not have any active call, and not be in a waiting state */ if (!p->owner && p->chan) { /* Fixed agent */ @@ -2007,7 +2008,7 @@ ast_mutex_lock(&agentlock); ast_mutex_lock(&p->lock); if (p->lastdisc.tv_sec) { - if (ast_tvdiff_ms(ast_tvnow(), p->lastdisc) > p->wrapuptime) { + if (ast_tvdiff_ms(ast_tvnow(), p->lastdisc) > 0) { if (option_debug) ast_log(LOG_DEBUG, "Wrapup time for %s expired!\n", p->agent); p->lastdisc = ast_tv(0, 0);