r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need
[vlendec/samba-autobuild/.git] / source3 / lib / debug.c
index b69a35ecd5c829f93cd8646f5f732604d7185e2c..bf75bdf3d3f516d3c03f397bc02183c602975e13 100644 (file)
@@ -164,6 +164,9 @@ static const char *default_classname_table[] = {
        "idmap",             /* DBGC_IDMAP        */
        "quota",             /* DBGC_QUOTA        */
        "acls",              /* DBGC_ACLS         */
+       "locking",           /* DBGC_LOCKING      */
+       "msdfs",             /* DBGC_MSDFS        */
+       "dmapi",             /* DBGC_DMAPI        */
        NULL
 };
 
@@ -174,6 +177,27 @@ static char **classname_table = NULL;
  * Functions...
  */
 
+/***************************************************************************
+ Free memory pointed to by global pointers.
+****************************************************************************/
+
+void gfree_debugsyms(void)
+{
+       int i;
+
+       if ( classname_table ) {
+               for ( i = 0; i < debug_num_classes; i++ ) {
+                       SAFE_FREE( classname_table[i] );
+               }
+               SAFE_FREE( classname_table );
+       }
+
+       if ( DEBUGLEVEL_CLASS != &debug_all_class_hack )
+               SAFE_FREE( DEBUGLEVEL_CLASS );
+
+       if ( DEBUGLEVEL_CLASS_ISSET != &debug_all_class_isset_hack )
+               SAFE_FREE( DEBUGLEVEL_CLASS_ISSET );
+}
 
 /****************************************************************************
 utility lists registered debug class names's
@@ -189,12 +213,14 @@ static char *debug_list_class_names_and_levels(void)
        char *b;
        BOOL err = False;
 
-       if (DEBUGLEVEL_CLASS == &debug_all_class_hack)
+       if (DEBUGLEVEL_CLASS == &debug_all_class_hack) {
                return NULL;
+       }
 
        list = SMB_CALLOC_ARRAY(char *, debug_num_classes + 1);
-       if (!list)
+       if (!list) {
                return NULL;
+       }
 
        /* prepare strings */
        for (i = 0, dim = 0; i < debug_num_classes; i++) {
@@ -225,13 +251,12 @@ static char *debug_list_class_names_and_levels(void)
 
 done:
        /* free strings list */
-       for (i = 0; i < debug_num_classes; i++)
-               if (list[i]) free(list[i]);
-       free(list);
+       for (i = 0; i < debug_num_classes; i++) {
+               SAFE_FREE(list[i]);
+       }
+       SAFE_FREE(list);
 
        if (err) {
-               if (buf)
-                       free(buf);
                return NULL;
        } else {
                return buf;
@@ -446,19 +471,22 @@ BOOL debug_parse_levels(const char *params_str)
  Receive a "set debug level" message.
 ****************************************************************************/
 
-static void debug_message(int msg_type, pid_t src, void *buf, size_t len)
+static void debug_message(int msg_type, struct process_id src,
+                         void *buf, size_t len)
 {
        const char *params_str = buf;
 
        /* Check, it's a proper string! */
        if (params_str[len-1] != '\0') {
                DEBUG(1, ("Invalid debug message from pid %u to pid %u\n",
-                         (unsigned int)src, (unsigned int)getpid()));
+                         (unsigned int)procid_to_pid(&src),
+                         (unsigned int)getpid()));
                return;
        }
 
        DEBUG(3, ("INFO: Remote set of debug to `%s'  (pid %u from pid %u)\n",
-                 params_str, (unsigned int)getpid(), (unsigned int)src));
+                 params_str, (unsigned int)getpid(),
+                 (unsigned int)procid_to_pid(&src)));
 
        debug_parse_levels(params_str);
 }
@@ -471,7 +499,8 @@ void debug_message_send(pid_t pid, const char *params_str)
 {
        if (!params_str)
                return;
-       message_send_pid(pid, MSG_DEBUG, params_str, strlen(params_str) + 1,
+       message_send_pid(pid_to_procid(pid), MSG_DEBUG,
+                        params_str, strlen(params_str) + 1,
                         False);
 }
 
@@ -479,11 +508,18 @@ void debug_message_send(pid_t pid, const char *params_str)
  Return current debug level.
 ****************************************************************************/
 
-static void debuglevel_message(int msg_type, pid_t src, void *buf, size_t len)
+static void debuglevel_message(int msg_type, struct process_id src,
+                              void *buf, size_t len)
 {
        char *message = debug_list_class_names_and_levels();
 
-       DEBUG(1,("INFO: Received REQ_DEBUGLEVEL message from PID %u\n",(unsigned int)src));
+       if (!message) {
+               DEBUG(0,("debuglevel_message - debug_list_class_names_and_levels returned NULL\n"));
+               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);
 
        SAFE_FREE(message);
@@ -500,7 +536,7 @@ void debug_init(void)
 
        if (initialised)
                return;
-       
+
        initialised = True;
 
        message_register(MSG_DEBUG, debug_message);
@@ -945,7 +981,7 @@ BOOL dbghdr( int level, const char *file, const char *func, int line )
   
                /* Print it all out at once to prevent split syslog output. */
                (void)Debug1( "[%s, %d%s] %s:%s(%d)\n",
-                       timestring(lp_debug_hires_timestamp()), level,
+                       current_timestring(lp_debug_hires_timestamp()), level,
                        header_str, file, func, line );
        }