LCOV - code coverage report
Current view: top level - source4/samba - server_util.c (source / functions) Hit Total Coverage
Test: coverage report for master 98b443d9 Lines: 22 28 78.6 %
Date: 2024-05-31 13:13:24 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    Utility routines
       5             : 
       6             :    Copyright (C) 2020 Ralph Boehme <slow@samba.org>
       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/tevent/tevent.h"
      24             : #include "lib/util/unix_privs.h"
      25             : #include "server_util.h"
      26             : 
      27             : struct samba_tevent_trace_state {
      28             :         size_t events;
      29             :         time_t last_logsize_check;
      30             : };
      31             : 
      32         177 : struct samba_tevent_trace_state *create_samba_tevent_trace_state(
      33             :         TALLOC_CTX *mem_ctx)
      34             : {
      35         177 :         return talloc_zero(mem_ctx, struct samba_tevent_trace_state);
      36             : }
      37             : 
      38    47967600 : void samba_tevent_trace_callback(enum tevent_trace_point point,
      39             :                                  void *private_data)
      40             : {
      41      188036 :         struct samba_tevent_trace_state *state =
      42    47967600 :                 talloc_get_type_abort(private_data,
      43             :                                       struct samba_tevent_trace_state);
      44    47967600 :         time_t now = time(NULL);
      45    47967600 :         bool do_check_logs = false;
      46    47967600 :         void *priv = NULL;
      47             : 
      48    47967600 :         switch (point) {
      49     9655947 :         case TEVENT_TRACE_BEFORE_WAIT:
      50     9687600 :                 break;
      51    38123617 :         default:
      52    38123617 :                 return;
      53             :         }
      54             : 
      55     9687600 :         state->events++;
      56             : 
      57             :         /*
      58             :          * Throttling by some random numbers. smbd uses a similar logic
      59             :          * checking every 50 SMB requests. Assuming 4 events per request
      60             :          * we get to the number of 200.
      61             :          */
      62     9687600 :         if ((state->events % 200) == 0) {
      63       48026 :                 do_check_logs = true;
      64             :         }
      65             :         /*
      66             :          * Throttling by some delay, choosing 29 to avoid lockstep with
      67             :          * the default tevent tickle timer.
      68             :          */
      69     9687600 :         if ((state->last_logsize_check + 29) < now) {
      70     9655947 :                 do_check_logs = true;
      71             :         }
      72             : 
      73     9655947 :         if (!do_check_logs) {
      74           0 :                 return;
      75             :         }
      76             : 
      77             :         /*
      78             :          * need_to_check_log_size() checks both the number of messages
      79             :          * that have been logged and if the logging backend is actually
      80             :          * going to file. We want to bypass the "number of messages"
      81             :          * check, so we have to call force_check_log_size() before.
      82             :          */
      83     9687600 :         force_check_log_size();
      84     9687600 :         if (!need_to_check_log_size()) {
      85     9655947 :                 return;
      86             :         }
      87             : 
      88           0 :         priv = root_privileges();
      89           0 :         check_log_size();
      90           0 :         TALLOC_FREE(priv);
      91             : 
      92           0 :         state->last_logsize_check = now;
      93           0 :         return;
      94             : }

Generated by: LCOV version 1.14