debug: Simplify dbghdrclass with an early return
authorVolker Lendecke <vl@samba.org>
Tue, 29 Jul 2014 15:02:22 +0000 (15:02 +0000)
committerMichael Adam <obnox@samba.org>
Thu, 31 Jul 2014 16:49:47 +0000 (18:49 +0200)
No code change, visible with "git diff -w"

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
lib/util/debug.c

index 3524a9a58c0c6009bdd4532ad8eaf9b30dd070f0..6dbf906177d4d639ed7226c3b8d1e03dd63d17aa 100644 (file)
@@ -969,6 +969,8 @@ bool dbghdrclass(int level, int cls, const char *location, const char *func)
 {
        /* Ensure we don't lose any real errno value. */
        int old_errno = errno;
+       bool verbose = false;
+       char header_str[200];
 
        if( format_pos ) {
                /* This is a fudge.  If there is stuff sitting in the format_bufr, then
@@ -994,53 +996,53 @@ bool dbghdrclass(int level, int cls, const char *location, const char *func)
        /* Print the header if timestamps are turned on.  If parameters are
         * not yet loaded, then default to timestamps on.
         */
-       if( state.settings.timestamp_logs || state.settings.debug_prefix_timestamp) {
-               bool verbose = false;
-               char header_str[200];
+       if (!(state.settings.timestamp_logs ||
+             state.settings.debug_prefix_timestamp)) {
+               return true;
+       }
 
-               header_str[0] = '\0';
+       header_str[0] = '\0';
 
-               if (unlikely(DEBUGLEVEL_CLASS[ cls ] >= 10)) {
-                       verbose = true;
-               }
+       if (unlikely(DEBUGLEVEL_CLASS[ cls ] >= 10)) {
+               verbose = true;
+       }
 
-               if (verbose || state.settings.debug_pid)
-                       slprintf(header_str,sizeof(header_str)-1,", pid=%u",(unsigned int)getpid());
+       if (verbose || state.settings.debug_pid)
+               slprintf(header_str,sizeof(header_str)-1,", pid=%u",(unsigned int)getpid());
 
-               if (verbose || state.settings.debug_uid) {
-                       size_t hs_len = strlen(header_str);
-                       slprintf(header_str + hs_len,
-                       sizeof(header_str) - 1 - hs_len,
-                               ", effective(%u, %u), real(%u, %u)",
-                               (unsigned int)geteuid(), (unsigned int)getegid(),
-                               (unsigned int)getuid(), (unsigned int)getgid());
-               }
+       if (verbose || state.settings.debug_uid) {
+               size_t hs_len = strlen(header_str);
+               slprintf(header_str + hs_len,
+                        sizeof(header_str) - 1 - hs_len,
+                        ", effective(%u, %u), real(%u, %u)",
+                        (unsigned int)geteuid(), (unsigned int)getegid(),
+                        (unsigned int)getuid(), (unsigned int)getgid());
+       }
 
-               if ((verbose || state.settings.debug_class)
-                   && (cls != DBGC_ALL)) {
-                       size_t hs_len = strlen(header_str);
-                       slprintf(header_str + hs_len,
-                                sizeof(header_str) -1 - hs_len,
-                                ", class=%s",
-                                classname_table[cls]);
-               }
+       if ((verbose || state.settings.debug_class)
+           && (cls != DBGC_ALL)) {
+               size_t hs_len = strlen(header_str);
+               slprintf(header_str + hs_len,
+                        sizeof(header_str) -1 - hs_len,
+                        ", class=%s",
+                        classname_table[cls]);
+       }
 
-               /* Print it all out at once to prevent split syslog output. */
-               if( state.settings.debug_prefix_timestamp ) {
-                       char *time_str = current_timestring(NULL,
-                                                           state.settings.debug_hires_timestamp);
-                       (void)Debug1( "[%s, %2d%s] ",
-                                     time_str,
-                                     level, header_str);
-                       talloc_free(time_str);
-               } else {
-                       char *time_str = current_timestring(NULL,
-                                                           state.settings.debug_hires_timestamp);
-                       (void)Debug1( "[%s, %2d%s] %s(%s)\n",
-                                     time_str,
-                                     level, header_str, location, func );
-                       talloc_free(time_str);
-               }
+       /* Print it all out at once to prevent split syslog output. */
+       if( state.settings.debug_prefix_timestamp ) {
+               char *time_str = current_timestring(NULL,
+                                                   state.settings.debug_hires_timestamp);
+               (void)Debug1( "[%s, %2d%s] ",
+                             time_str,
+                             level, header_str);
+               talloc_free(time_str);
+       } else {
+               char *time_str = current_timestring(NULL,
+                                                   state.settings.debug_hires_timestamp);
+               (void)Debug1( "[%s, %2d%s] %s(%s)\n",
+                             time_str,
+                             level, header_str, location, func );
+               talloc_free(time_str);
        }
 
        errno = old_errno;