debug: add logfile and fd to struct debug_class
authorRalph Boehme <slow@samba.org>
Wed, 12 Dec 2018 11:51:16 +0000 (12:51 +0100)
committerJeremy Allison <jra@samba.org>
Thu, 20 Dec 2018 02:19:26 +0000 (03:19 +0100)
Initialized to -1. Already checked in debug_file_log() without affecting
behaviour until subsequent commits set per-debug-class fds.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/util/debug.c

index 2174add2a6c817ecbe8ebf9ec4c9d083f811fa37..d01bde7a47913c5c68a05951a0b1ab7f705fd845 100644 (file)
@@ -108,6 +108,13 @@ struct debug_class {
         * The debug loglevel of the class.
         */
        int loglevel;
+
+       /*
+        * An optional class specific logfile, may be NULL in which case the
+        * "global" logfile is used and fd is -1.
+        */
+       char *logfile;
+       int fd;
 };
 
 static const char *default_classname_table[] = {
@@ -201,10 +208,18 @@ static void debug_file_log(int msg_level,
                           const char *msg, const char *msg_no_nl)
 {
        ssize_t ret;
+       int fd;
 
        check_log_size();
+
+       if (dbgc_config[current_msg_class].fd != -1) {
+               fd = dbgc_config[current_msg_class].fd;
+       } else {
+               fd = state.fd;
+       }
+
        do {
-               ret = write(state.fd, msg, strlen(msg));
+               ret = write(fd, msg, strlen(msg));
        } while (ret == -1 && errno == EINTR);
 }
 
@@ -735,6 +750,7 @@ int debug_add_class(const char *classname)
 
        dbgc_config[ndx] = (struct debug_class) {
                .loglevel = default_level,
+               .fd = -1,
        };
 
        new_name_list = talloc_realloc(NULL, classname_table, char *, ndx + 1);