LCOV - code coverage report
Current view: top level - source4/wrepl_server - wrepl_periodic.c (source / functions) Hit Total Coverage
Test: coverage report for master 2b515b7d Lines: 42 45 93.3 %
Date: 2024-02-28 12:06:22 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             :    
       4             :    WINS Replication server
       5             :    
       6             :    Copyright (C) Stefan Metzmacher      2005
       7             :    
       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.
      12             :    
      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.
      17             :    
      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/>.
      20             : */
      21             : 
      22             : #include "includes.h"
      23             : #include "lib/events/events.h"
      24             : #include "samba/service_task.h"
      25             : #include "samba/service.h"
      26             : #include "librpc/gen_ndr/winsrepl.h"
      27             : #include "wrepl_server/wrepl_server.h"
      28             : 
      29        3584 : static NTSTATUS wreplsrv_periodic_run(struct wreplsrv_service *service)
      30             : {
      31          31 :         NTSTATUS status;
      32             : 
      33        3584 :         status = wreplsrv_load_partners(service);
      34        3584 :         NT_STATUS_NOT_OK_RETURN(status);
      35             : 
      36        3584 :         status = wreplsrv_scavenging_run(service);
      37        3584 :         NT_STATUS_NOT_OK_RETURN(status);
      38             : 
      39        3584 :         status = wreplsrv_out_pull_run(service);
      40        3584 :         NT_STATUS_NOT_OK_RETURN(status);
      41             : 
      42        3584 :         status = wreplsrv_out_push_run(service);
      43        3584 :         NT_STATUS_NOT_OK_RETURN(status);
      44             : 
      45        3584 :         return NT_STATUS_OK;
      46             : }
      47             : 
      48        3584 : static void wreplsrv_periodic_handler_te(struct tevent_context *ev, struct tevent_timer *te,
      49             :                                          struct timeval t, void *ptr)
      50             : {
      51        3584 :         struct wreplsrv_service *service = talloc_get_type(ptr, struct wreplsrv_service);
      52          31 :         NTSTATUS status;
      53             : 
      54        3584 :         service->periodic.te = NULL;
      55             : 
      56        3584 :         status = wreplsrv_periodic_schedule(service, service->config.periodic_interval);
      57        3584 :         if (!NT_STATUS_IS_OK(status)) {
      58           0 :                 task_server_terminate(service->task, nt_errstr(status), false);
      59           0 :                 return;
      60             :         }
      61             : 
      62        3584 :         status = wreplsrv_periodic_run(service);
      63        3584 :         if (!NT_STATUS_IS_OK(status)) {
      64           0 :                 DEBUG(0,("wresrv_periodic_run() failed: %s\n", nt_errstr(status)));
      65             :         }
      66             : }
      67             : 
      68        3714 : NTSTATUS wreplsrv_periodic_schedule(struct wreplsrv_service *service, uint32_t next_interval)
      69             : {
      70          35 :         TALLOC_CTX *tmp_mem;
      71          35 :         struct tevent_timer *new_te;
      72          35 :         struct timeval next_time;
      73             : 
      74             :         /* prevent looping */
      75        3714 :         if (next_interval == 0) next_interval = 1;
      76             : 
      77        3714 :         next_time = timeval_current_ofs(next_interval, 5000);
      78             : 
      79        3714 :         if (service->periodic.te) {
      80             :                 /*
      81             :                  * if the timestamp of the new event is higher,
      82             :                  * as current next we don't need to reschedule
      83             :                  */
      84          65 :                 if (timeval_compare(&next_time, &service->periodic.next_event) > 0) {
      85          65 :                         return NT_STATUS_OK;
      86             :                 }
      87             :         }
      88             : 
      89             :         /* reset the next scheduled timestamp */
      90        3649 :         service->periodic.next_event = next_time;
      91             : 
      92        3649 :         new_te = tevent_add_timer(service->task->event_ctx, service,
      93             :                                  service->periodic.next_event,
      94             :                                  wreplsrv_periodic_handler_te, service);
      95        3649 :         NT_STATUS_HAVE_NO_MEMORY(new_te);
      96             : 
      97        3649 :         tmp_mem = talloc_new(service);
      98        3649 :         DEBUG(6,("wreplsrv_periodic_schedule(%u) %sscheduled for: %s\n",
      99             :                 next_interval,
     100             :                 (service->periodic.te?"re":""),
     101             :                 nt_time_string(tmp_mem, timeval_to_nttime(&next_time))));
     102        3649 :         talloc_free(tmp_mem);
     103             : 
     104        3649 :         talloc_free(service->periodic.te);
     105        3649 :         service->periodic.te = new_te;
     106             : 
     107        3649 :         return NT_STATUS_OK;
     108             : }
     109             : 
     110          65 : NTSTATUS wreplsrv_setup_periodic(struct wreplsrv_service *service)
     111             : {
     112           2 :         NTSTATUS status;
     113             : 
     114          65 :         status = wreplsrv_periodic_schedule(service, 0);
     115          65 :         NT_STATUS_NOT_OK_RETURN(status);
     116             : 
     117          65 :         return NT_STATUS_OK;
     118             : }

Generated by: LCOV version 1.14