From f2d1d8fed61e0bb683756d692ed00b2a35c8d06c Mon Sep 17 00:00:00 2001 From: Dave Parker Date: Tue, 30 Jun 2015 00:12:25 +0000 Subject: [PATCH] PrismNative: Use setvbuf() to set stdout to line-buffered. By default, stdout is line-buffered when connected to a tty but completely buffered when redirected to a file or piped to another program. This makes it hard to get an accurate picture of the current log output and state of a running PRISM instance by looking at a log file or terminal output for something like 'prism ... | tee log-file'. On the other hand, we don't want to call .flush() on the logs all the time manually. By using setvbuf, we set stdout to line-buffered, i.e., it will be flushed automatically for every line-ending. By passing NULL as the buffer pointer, we ask the libc to construct a buffer, passing 1024 as a (reasonable) hint for the buffer size, even for long lines. [from Joachim Klein] git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@10127 bbc10eb1-c90d-0410-af57-cb519fbb1720 --- prism/src/prism/PrismNative.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/prism/src/prism/PrismNative.cc b/prism/src/prism/PrismNative.cc index a8fe3af5..e4b2d75f 100644 --- a/prism/src/prism/PrismNative.cc +++ b/prism/src/prism/PrismNative.cc @@ -185,6 +185,7 @@ JNIEXPORT void JNICALL Java_prism_PrismNative_PN_1SetExportAdvFilename(JNIEnv *e JNIEXPORT jlong __jlongpointer JNICALL Java_prism_PrismNative_PN_1GetStdout(JNIEnv *env, jclass cls) { + setvbuf(stdout, NULL, _IOLBF, 1024); return ptr_to_jlong(stdout); }