r23779: Change from v2 or later to v3 or later.
[amitay/samba.git] / source3 / lib / debug.c
index a2e8574bbdd660b0bc0659d287622211e751b6a0..1ee5967a5613cc3f26976264521722b9293c543a 100644 (file)
@@ -7,7 +7,7 @@
 
    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
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
@@ -471,13 +471,16 @@ BOOL debug_parse_levels(const char *params_str)
  Receive a "set debug level" message.
 ****************************************************************************/
 
-static void debug_message(int msg_type, struct process_id src,
-                         void *buf, size_t len, void *private_data)
+static void debug_message(struct messaging_context *msg_ctx,
+                         void *private_data, 
+                         uint32_t msg_type, 
+                         struct server_id src,
+                         DATA_BLOB *data)
 {
-       const char *params_str = (const char *)buf;
+       const char *params_str = (const char *)data->data;
 
        /* Check, it's a proper string! */
-       if (params_str[len-1] != '\0') {
+       if (params_str[(data->length)-1] != '\0') {
                DEBUG(1, ("Invalid debug message from pid %u to pid %u\n",
                          (unsigned int)procid_to_pid(&src),
                          (unsigned int)getpid()));
@@ -491,25 +494,15 @@ static void debug_message(int msg_type, struct process_id src,
        debug_parse_levels(params_str);
 }
 
-/****************************************************************************
- Send a "set debug level" message.
-****************************************************************************/
-
-void debug_message_send(pid_t pid, const char *params_str)
-{
-       if (!params_str)
-               return;
-       message_send_pid(pid_to_procid(pid), MSG_DEBUG,
-                        params_str, strlen(params_str) + 1,
-                        False);
-}
-
 /****************************************************************************
  Return current debug level.
 ****************************************************************************/
 
-static void debuglevel_message(int msg_type, struct process_id src,
-                              void *buf, size_t len, void *private_data)
+static void debuglevel_message(struct messaging_context *msg_ctx,
+                              void *private_data, 
+                              uint32_t msg_type, 
+                              struct server_id src,
+                              DATA_BLOB *data)
 {
        char *message = debug_list_class_names_and_levels();
 
@@ -518,9 +511,10 @@ static void debuglevel_message(int msg_type, struct process_id src,
                return;
        }
 
-       DEBUG(1,("INFO: Received REQ_DEBUGLEVEL message from PID %u\n",
-                (unsigned int)procid_to_pid(&src)));
-       message_send_pid(src, MSG_DEBUGLEVEL, message, strlen(message) + 1, True);
+       DEBUG(1,("INFO: Received REQ_DEBUGLEVEL message from PID %s\n",
+                procid_str_static(&src)));
+       messaging_send_buf(msg_ctx, src, MSG_DEBUGLEVEL,
+                          (uint8 *)message, strlen(message) + 1);
 
        SAFE_FREE(message);
 }
@@ -539,14 +533,18 @@ void debug_init(void)
 
        initialised = True;
 
-       message_register(MSG_DEBUG, debug_message, NULL);
-       message_register(MSG_REQ_DEBUGLEVEL, debuglevel_message, NULL);
-
        for(p = default_classname_table; *p; p++) {
                debug_add_class(*p);
        }
 }
 
+void debug_register_msgs(struct messaging_context *msg_ctx)
+{
+       messaging_register(msg_ctx, NULL, MSG_DEBUG, debug_message);
+       messaging_register(msg_ctx, NULL, MSG_REQ_DEBUGLEVEL,
+                          debuglevel_message);
+}
+
 /***************************************************************************
  Get ready for syslog stuff
 **************************************************************************/
@@ -688,15 +686,20 @@ void check_log_size( void )
        int         maxlog;
        SMB_STRUCT_STAT st;
 
+       /*
+        *  We need to be root to check/change log-file, skip this and let the main
+        *  loop check do a new check as root.
+        */
+
+       if( geteuid() != 0 )
+               return;
+
        if(log_overflow || !need_to_check_log_size() )
                return;
 
        maxlog = lp_max_log_size() * 1024;
 
        if( sys_fstat( x_fileno( dbf ), &st ) == 0 && st.st_size > maxlog ) {
-
-               become_root_uid_only();
-
                (void)reopen_logs();
                if( dbf && get_file_size( debugf ) > maxlog ) {
                        pstring name;
@@ -709,8 +712,6 @@ void check_log_size( void )
                                (void)rename(name, debugf);
                        }
                }
-
-               unbecome_root_uid_only();
        }
 
        /*
@@ -978,7 +979,7 @@ BOOL dbghdr( int level, const char *file, const char *func, int line )
   
                /* Print it all out at once to prevent split syslog output. */
                if( lp_debug_prefix_timestamp() ) {
-                   (void)Debug1( "[%s, %d%s] ",
+                   (void)Debug1( "[%s, %2d%s] ",
                        current_timestring(lp_debug_hires_timestamp()), level,
                        header_str);
                } else {