2
Unix SMB/CIFS implementation.
4
WINS Replication server
6
Copyright (C) Stefan Metzmacher 2005
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 3 of the License, or
11
(at your option) any later version.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with this program. If not, see <http://www.gnu.org/licenses/>.
23
#include "lib/events/events.h"
24
#include "smbd/service_task.h"
25
#include "smbd/service.h"
26
#include "librpc/gen_ndr/winsrepl.h"
27
#include "wrepl_server/wrepl_server.h"
29
static NTSTATUS wreplsrv_periodic_run(struct wreplsrv_service *service)
33
status = wreplsrv_load_partners(service);
34
NT_STATUS_NOT_OK_RETURN(status);
36
status = wreplsrv_scavenging_run(service);
37
NT_STATUS_NOT_OK_RETURN(status);
39
status = wreplsrv_out_pull_run(service);
40
NT_STATUS_NOT_OK_RETURN(status);
42
status = wreplsrv_out_push_run(service);
43
NT_STATUS_NOT_OK_RETURN(status);
48
static void wreplsrv_periodic_handler_te(struct tevent_context *ev, struct tevent_timer *te,
49
struct timeval t, void *ptr)
51
struct wreplsrv_service *service = talloc_get_type(ptr, struct wreplsrv_service);
54
service->periodic.te = NULL;
56
status = wreplsrv_periodic_schedule(service, service->config.periodic_interval);
57
if (!NT_STATUS_IS_OK(status)) {
58
task_server_terminate(service->task, nt_errstr(status));
62
status = wreplsrv_periodic_run(service);
63
if (!NT_STATUS_IS_OK(status)) {
64
DEBUG(0,("wresrv_periodic_run() failed: %s\n", nt_errstr(status)));
68
NTSTATUS wreplsrv_periodic_schedule(struct wreplsrv_service *service, uint32_t next_interval)
71
struct tevent_timer *new_te;
72
struct timeval next_time;
75
if (next_interval == 0) next_interval = 1;
77
next_time = timeval_current_ofs(next_interval, 5000);
79
if (service->periodic.te) {
81
* if the timestamp of the new event is higher,
82
* as current next we don't need to reschedule
84
if (timeval_compare(&next_time, &service->periodic.next_event) > 0) {
89
/* reset the next scheduled timestamp */
90
service->periodic.next_event = next_time;
92
new_te = event_add_timed(service->task->event_ctx, service,
93
service->periodic.next_event,
94
wreplsrv_periodic_handler_te, service);
95
NT_STATUS_HAVE_NO_MEMORY(new_te);
97
tmp_mem = talloc_new(service);
98
DEBUG(6,("wreplsrv_periodic_schedule(%u) %sscheduled for: %s\n",
100
(service->periodic.te?"re":""),
101
nt_time_string(tmp_mem, timeval_to_nttime(&next_time))));
102
talloc_free(tmp_mem);
104
talloc_free(service->periodic.te);
105
service->periodic.te = new_te;
110
NTSTATUS wreplsrv_setup_periodic(struct wreplsrv_service *service)
114
status = wreplsrv_periodic_schedule(service, 0);
115
NT_STATUS_NOT_OK_RETURN(status);