LCOV - code coverage report
Current view: top level - lib/util - debug_s3.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 24 51 47.1 %
Date: 2024-04-21 15:09:00 Functions: 2 5 40.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    Samba utility functions
       4             :    Copyright (C) Andrew Bartlett 2011
       5             :    Copyright (C) Andrew Tridgell 1992-2002
       6             : 
       7             :    This program is free software; you can redistribute it and/or modify
       8             :    it under the terms of the GNU General Public License as published by
       9             :    the Free Software Foundation; either version 3 of the License, or
      10             :    (at your option) any later version.
      11             : 
      12             :    This program is distributed in the hope that it will be useful,
      13             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :    GNU General Public License for more details.
      16             : 
      17             :    You should have received a copy of the GNU General Public License
      18             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      19             : */
      20             : 
      21             : #include "includes.h"
      22             : #include "lib/util/server_id.h"
      23             : #include "librpc/gen_ndr/messaging.h"
      24             : #include "messages.h"
      25             : #include "lib/util/memory.h"
      26             : 
      27             : /* This is the Samba3-specific implementation of reopen_logs(), which
      28             :  * calls out to the s3 loadparm code, and means that we don't depend
      29             :  * on loadparm directly. */
      30             : 
      31      155322 : bool reopen_logs(void)
      32             : {
      33      155322 :         if (lp_loaded()) {
      34     1397898 :                 struct debug_settings settings = {
      35      155322 :                         .max_log_size = lp_max_log_size(),
      36      155322 :                         .timestamp_logs = lp_timestamp_logs(),
      37      155322 :                         .debug_prefix_timestamp = lp_debug_prefix_timestamp(),
      38      155322 :                         .debug_hires_timestamp = lp_debug_hires_timestamp(),
      39      155322 :                         .debug_syslog_format = lp_debug_syslog_format(),
      40      155322 :                         .debug_pid = lp_debug_pid(),
      41      155322 :                         .debug_uid = lp_debug_uid(),
      42      155322 :                         .debug_class = lp_debug_class(),
      43             :                 };
      44        3835 :                 const struct loadparm_substitution *lp_sub =
      45      155322 :                         loadparm_s3_global_substitution();
      46             : 
      47      155322 :                 debug_set_logfile(lp_logfile(talloc_tos(), lp_sub));
      48      155322 :                 debug_parse_levels(lp_log_level(talloc_tos(), lp_sub));
      49      310644 :                 debug_set_settings(&settings,
      50      155322 :                                    lp_logging(talloc_tos(), lp_sub),
      51             :                                    lp_syslog(),
      52      155322 :                                    lp_syslog_only());
      53             :         } else {
      54             :                 /*
      55             :                  * Parameters are not yet loaded - configure debugging with
      56             :                  * reasonable defaults to enable logging for early
      57             :                  * startup failures.
      58             :                  */
      59           0 :                 struct debug_settings settings = {
      60             :                         .max_log_size = 5000,
      61             :                         .timestamp_logs = true,
      62             :                         .debug_prefix_timestamp = false,
      63             :                         .debug_hires_timestamp = true,
      64             :                         .debug_syslog_format = false,
      65             :                         .debug_pid = false,
      66             :                         .debug_uid = false,
      67             :                         .debug_class = false,
      68             :                 };
      69           0 :                 debug_set_settings(&settings,
      70             :                                    "file",
      71             :                                    1,
      72             :                                    false);
      73             :         }
      74      155322 :         return reopen_logs_internal();
      75             : }
      76             : 
      77             : /****************************************************************************
      78             :  Receive a "set debug level" message.
      79             : ****************************************************************************/
      80             : 
      81           0 : void debug_message(struct messaging_context *msg_ctx,
      82             :                           void *private_data,
      83             :                           uint32_t msg_type,
      84             :                           struct server_id src,
      85             :                           DATA_BLOB *data)
      86             : {
      87           0 :         const char *params_str = (const char *)data->data;
      88             : 
      89             :         /* Check, it's a proper string! */
      90           0 :         if (params_str[(data->length)-1] != '\0') {
      91           0 :                 DEBUG(1, ("Invalid debug message from pid %u to pid %u\n",
      92             :                           (unsigned int)procid_to_pid(&src),
      93             :                           (unsigned int)getpid()));
      94           0 :                 return;
      95             :         }
      96             : 
      97           0 :         DEBUG(3, ("INFO: Remote set of debug to `%s'  (pid %u from pid %u)\n",
      98             :                   params_str, (unsigned int)getpid(),
      99             :                   (unsigned int)procid_to_pid(&src)));
     100             : 
     101           0 :         debug_parse_levels(params_str);
     102             : }
     103             : 
     104             : /****************************************************************************
     105             :  Return current debug level.
     106             : ****************************************************************************/
     107             : 
     108           0 : static void debuglevel_message(struct messaging_context *msg_ctx,
     109             :                                void *private_data, 
     110             :                                uint32_t msg_type, 
     111             :                                struct server_id src,
     112             :                                DATA_BLOB *data)
     113             : {
     114           0 :         char *message = debug_list_class_names_and_levels();
     115           0 :         struct server_id_buf tmp;
     116             : 
     117           0 :         if (!message) {
     118           0 :                 DEBUG(0,("debuglevel_message - debug_list_class_names_and_levels returned NULL\n"));
     119           0 :                 return;
     120             :         }
     121             : 
     122           0 :         DEBUG(1, ("INFO: Received REQ_DEBUGLEVEL message from PID %s\n",
     123             :                   server_id_str_buf(src, &tmp)));
     124           0 :         messaging_send_buf(msg_ctx, src, MSG_DEBUGLEVEL,
     125           0 :                            (uint8_t *)message, strlen(message) + 1);
     126             : 
     127           0 :         TALLOC_FREE(message);
     128             : }
     129             : 
     130           0 : static void debug_ringbuf_log(struct messaging_context *msg_ctx,
     131             :                               void *private_data,
     132             :                               uint32_t msg_type,
     133             :                               struct server_id src,
     134             :                               DATA_BLOB *data)
     135             : {
     136           0 :         char *log = debug_get_ringbuf();
     137           0 :         size_t logsize = debug_get_ringbuf_size();
     138             : 
     139           0 :         if (log == NULL) {
     140           0 :                 log = discard_const_p(char, "*disabled*\n");
     141           0 :                 logsize = strlen(log) + 1;
     142             :         }
     143             : 
     144           0 :         messaging_send_buf(msg_ctx, src, MSG_RINGBUF_LOG, (uint8_t *)log,
     145             :                            logsize);
     146           0 : }
     147             : 
     148        5200 : void debug_register_msgs(struct messaging_context *msg_ctx)
     149             : {
     150        5200 :         messaging_register(msg_ctx, NULL, MSG_DEBUG, debug_message);
     151        5200 :         messaging_register(msg_ctx, NULL, MSG_REQ_DEBUGLEVEL,
     152             :                            debuglevel_message);
     153        5200 :         messaging_register(msg_ctx, NULL, MSG_REQ_RINGBUF_LOG,
     154             :                            debug_ringbuf_log);
     155        5200 : }

Generated by: LCOV version 1.14