]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
file-logger: Emulate setlinebuf() if not supported by using fflush()
authorMartin Willi <martin@revosec.ch>
Wed, 5 Mar 2014 15:28:38 +0000 (16:28 +0100)
committerMartin Willi <martin@revosec.ch>
Wed, 4 Jun 2014 13:53:09 +0000 (15:53 +0200)
src/libcharon/bus/listeners/file_logger.c

index c86cff132f1da96dafd5b18e04a7404e5d9ca20b..e3661bde6ea8ef8e7725276399edc24581150cd8 100644 (file)
@@ -49,6 +49,11 @@ struct private_file_logger_t {
         */
        FILE *out;
 
+       /**
+        * Flush after writing a line?
+        */
+       bool flush_line;
+
        /**
         * Maximum level to log, for each group
         */
@@ -137,6 +142,12 @@ METHOD(logger_t, log_, void,
                fprintf(this->out, "%.*s\n", (int)(next - current), current);
                current = next + 1;
        }
+#ifndef HAVE_SETLINEBUF
+       if (this->flush_line)
+       {
+               fflush(this->out);
+       }
+#endif /* !HAVE_SETLINEBUF */
        this->mutex->unlock(this->mutex);
        this->lock->unlock(this->lock);
 }
@@ -224,6 +235,7 @@ METHOD(file_logger_t, open_, void,
        this->lock->write_lock(this->lock);
        close_file(this);
        this->out = file;
+       this->flush_line = flush_line;
        this->lock->unlock(this->lock);
 }