From: Olaf Hering Subject: [PATCH 2 of 7] tools/xc: handle tty output differently in stdiostream_progress Date: Wed, 13 Feb 2013 16:53:00 +0100 Message-ID: <1518e1b1341a56e8ea52.1360770780@probook.site> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org # HG changeset patch # User Olaf Hering # Date 1360769525 -3600 # Node ID 1518e1b1341a56e8ea52c7fbaa56a7c062e559a5 # Parent d13841ebeb080e3dea9b865d79e194e81d6aa2db tools/xc: handle tty output differently in stdiostream_progress If the output goes to a tty, rewind the cursor and print everything in a single line as it was done up to now. If the output goes to a file or pipe print a newline after each progress output. This will fix logging of progress messages from xc_save to xend.log. To support XTL_STDIOSTREAM_SHOW_PID or XTL_STDIOSTREAM_SHOW_DATE print the output via vmessage if the output is not a tty. Signed-off-by: Olaf Hering diff -r d13841ebeb08 -r 1518e1b1341a tools/libxc/xtl_logger_stdio.c --- a/tools/libxc/xtl_logger_stdio.c +++ b/tools/libxc/xtl_logger_stdio.c @@ -81,6 +81,17 @@ static void stdiostream_vmessage(xentool fflush(lg->f); } +static void stdiostream_message(struct xentoollog_logger *logger_in, + xentoollog_level level, + const char *context, + const char *format, ...) +{ + va_list al; + va_start(al,format); + stdiostream_vmessage(logger_in, level, -1, context, format, al); + va_end(al); +} + static void stdiostream_progress(struct xentoollog_logger *logger_in, const char *context, const char *doing_what, int percent, @@ -105,11 +116,18 @@ static void stdiostream_progress(struct if (this_level < lg->min_level) return; + lg->progress_last_percent = percent; + + if (isatty(fileno(lg->f)) <= 0) { + stdiostream_message(logger_in, this_level, context, + "%s: %lu/%lu %3d%%", + doing_what, done, total, percent); + return; + } + if (lg->progress_erase_len) putc('\r', lg->f); - lg->progress_last_percent = percent; - newpel = fprintf(lg->f, "%s%s" "%s: %lu/%lu %3d%%%s", context?context:"", context?": ":"", doing_what, done, total, percent,