Blame SOURCES/rlRun-output.patch

e965a0
--- a/src/testing.sh	2018-02-24 14:44:24.213182846 +0100
e965a0
+++ b/src/testing.sh	2018-02-24 14:44:58.046031444 +0100
e965a0
@@ -731,6 +731,12 @@
e965a0
 Be aware that there are some variables which can collide with your code executed
e965a0
 within rlRun. You should avoid using __INTERNAL_rlRun_* variables.
e965a0
 
e965a0
+=item
e965a0
+
e965a0
+When any of C<-t> C<-l>, C<-c>, or C<-s> option is used, special file
e965a0
+descriptors 111 and 112 are used to avoid the issue with incomplete log file,
e965a0
+bz1361246.
e965a0
+
e965a0
 =back
e965a0
 
e965a0
 B<Warning:> using C<unbuffer> tool is now disabled because of bug 547686.
e965a0
@@ -848,9 +854,28 @@
e965a0
     __INTERNAL_PrintText "$__INTERNAL_rlRun_comment_begin" "BEGIN"
e965a0
 
e965a0
     if $__INTERNAL_rlRun_DO_LOG || $__INTERNAL_rlRun_DO_TAG || $__INTERNAL_rlRun_DO_KEEP; then
e965a0
-        eval "$__INTERNAL_rlRun_command" 2> >(sed -u -e "s/^/$__INTERNAL_rlRun_TAG_ERR/g" |
e965a0
-                tee -a $__INTERNAL_rlRun_LOG_FILE) 1> >(sed -u -e "s/^/$__INTERNAL_rlRun_TAG_OUT/g" | tee -a $__INTERNAL_rlRun_LOG_FILE)
e965a0
+        # handle issue with incomplete logs (bz1361246), this could be improved using coproc
e965a0
+        # in RHEL-6 and higher
e965a0
+        # open file descriptors to parsing processes
e965a0
+        exec 111> >(sed -u -e "s/^/$__INTERNAL_rlRun_TAG_OUT/g" | tee -a $__INTERNAL_rlRun_LOG_FILE)
e965a0
+        local __INTERNAL_rlRun_OUTpid=$!
e965a0
+        exec 112> >(sed -u -e "s/^/$__INTERNAL_rlRun_TAG_ERR/g" | tee -a $__INTERNAL_rlRun_LOG_FILE)
e965a0
+        local __INTERNAL_rlRun_ERRpid=$!
e965a0
+        eval "$__INTERNAL_rlRun_command" 2>&112 1>&111
e965a0
         local __INTERNAL_rlRun_exitcode=$?
e965a0
+        # close parsing processes
e965a0
+        exec 111>&-
e965a0
+        exec 112>&-
e965a0
+        # wait for parsing processes to finish their job
e965a0
+        local __INTERNAL_rlRun_counter=0
e965a0
+        while kill -0 $__INTERNAL_rlRun_OUTpid 2>/dev/null || kill -0 $__INTERNAL_rlRun_ERRpid 2>/dev/null; do
e965a0
+          [[ $((__INTERNAL_rlRun_counter++)) -gt 12000 ]] && {
e965a0
+            rlLogError "waiting for flushing the output timed out, there might be some data missing in the output file"
e965a0
+            break
e965a0
+          }
e965a0
+          sleep 0.01;
e965a0
+        done
e965a0
+        rlLogDebug "waiting for parsing processes took $__INTERNAL_rlRun_counter cycles"
e965a0
     else
e965a0
         eval "$__INTERNAL_rlRun_command"
e965a0
         local __INTERNAL_rlRun_exitcode=$?