2005-12-14 13:56:43 +03:00
/*
Unix SMB / CIFS implementation .
WINS Replication server
Copyright ( C ) Stefan Metzmacher 2005
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-10 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2005-12-14 13:56:43 +03:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2005-12-14 13:56:43 +03:00
*/
# include "includes.h"
# include "lib/events/events.h"
2020-11-20 17:27:17 +03:00
# include "samba/service_task.h"
# include "samba/service.h"
2006-03-16 03:23:11 +03:00
# include "librpc/gen_ndr/winsrepl.h"
2005-12-14 13:56:43 +03:00
# include "wrepl_server/wrepl_server.h"
2005-12-20 00:52:37 +03:00
static NTSTATUS wreplsrv_periodic_run ( struct wreplsrv_service * service )
2005-12-14 13:56:43 +03:00
{
2005-12-20 00:52:37 +03:00
NTSTATUS status ;
2006-01-03 23:19:39 +03:00
status = wreplsrv_load_partners ( service ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
2005-12-22 14:40:14 +03:00
status = wreplsrv_scavenging_run ( service ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
2005-12-20 03:55:28 +03:00
status = wreplsrv_out_pull_run ( service ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
2005-12-20 00:52:37 +03:00
status = wreplsrv_out_push_run ( service ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
2005-12-14 22:19:43 +03:00
2005-12-20 00:52:37 +03:00
return NT_STATUS_OK ;
2005-12-14 13:56:43 +03:00
}
2008-12-29 22:24:57 +03:00
static void wreplsrv_periodic_handler_te ( struct tevent_context * ev , struct tevent_timer * te ,
2005-12-14 13:56:43 +03:00
struct timeval t , void * ptr )
{
struct wreplsrv_service * service = talloc_get_type ( ptr , struct wreplsrv_service ) ;
2005-12-20 00:52:37 +03:00
NTSTATUS status ;
2005-12-14 13:56:43 +03:00
service - > periodic . te = NULL ;
2005-12-20 00:52:37 +03:00
status = wreplsrv_periodic_schedule ( service , service - > config . periodic_interval ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2009-09-19 05:05:55 +04:00
task_server_terminate ( service - > task , nt_errstr ( status ) , false ) ;
2005-12-14 13:56:43 +03:00
return ;
}
2005-12-20 00:52:37 +03:00
status = wreplsrv_periodic_run ( service ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 0 , ( " wresrv_periodic_run() failed: %s \n " , nt_errstr ( status ) ) ) ;
}
}
NTSTATUS wreplsrv_periodic_schedule ( struct wreplsrv_service * service , uint32_t next_interval )
{
TALLOC_CTX * tmp_mem ;
2008-12-29 22:24:57 +03:00
struct tevent_timer * new_te ;
2005-12-20 00:52:37 +03:00
struct timeval next_time ;
/* prevent looping */
if ( next_interval = = 0 ) next_interval = 1 ;
2005-12-20 03:55:28 +03:00
next_time = timeval_current_ofs ( next_interval , 5000 ) ;
2005-12-20 00:52:37 +03:00
if ( service - > periodic . te ) {
/*
* if the timestamp of the new event is higher ,
* as current next we don ' t need to reschedule
*/
if ( timeval_compare ( & next_time , & service - > periodic . next_event ) > 0 ) {
return NT_STATUS_OK ;
}
}
/* reset the next scheduled timestamp */
service - > periodic . next_event = next_time ;
2010-05-25 23:29:14 +04:00
new_te = tevent_add_timer ( service - > task - > event_ctx , service ,
2005-12-20 00:52:37 +03:00
service - > periodic . next_event ,
wreplsrv_periodic_handler_te , service ) ;
NT_STATUS_HAVE_NO_MEMORY ( new_te ) ;
tmp_mem = talloc_new ( service ) ;
2006-01-03 23:19:39 +03:00
DEBUG ( 6 , ( " wreplsrv_periodic_schedule(%u) %sscheduled for: %s \n " ,
2005-12-20 00:52:37 +03:00
next_interval ,
( service - > periodic . te ? " re " : " " ) ,
nt_time_string ( tmp_mem , timeval_to_nttime ( & next_time ) ) ) ) ;
talloc_free ( tmp_mem ) ;
talloc_free ( service - > periodic . te ) ;
service - > periodic . te = new_te ;
return NT_STATUS_OK ;
2005-12-14 13:56:43 +03:00
}
NTSTATUS wreplsrv_setup_periodic ( struct wreplsrv_service * service )
{
NTSTATUS status ;
2005-12-20 00:52:37 +03:00
status = wreplsrv_periodic_schedule ( service , 0 ) ;
NT_STATUS_NOT_OK_RETURN ( status ) ;
2005-12-14 13:56:43 +03:00
return NT_STATUS_OK ;
}