From: Ian Jackson Subject: [PATCH 1/5] xentoollog: provide XTL_STDIOSTREAM_PROGRESS_USE_CR Date: Mon, 17 Mar 2014 16:03:15 +0000 Message-ID: <1395072199-326-2-git-send-email-ian.jackson@eu.citrix.com> References: <1395072199-326-1-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1395072199-326-1-git-send-email-ian.jackson@eu.citrix.com> 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.xensource.com Cc: Olaf Hering , Ian Jackson , Ian Campbell List-Id: xen-devel@lists.xenproject.org Provide flags XTL_STDIOSTREAM_PROGRESS_USE_CR XTL_STDIOSTREAM_PROGRESS_NO_CR to allow the caller to force, or disable, the use of \r-based overwriting of progress messages. In the implementation, rename the variable "tty" to "progress_use_cr". Signed-off-by: Ian Jackson CC: Olaf Hering CC: Ian Campbell --- tools/libxc/xentoollog.h | 8 +++++--- tools/libxc/xtl_logger_stdio.c | 18 +++++++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/tools/libxc/xentoollog.h b/tools/libxc/xentoollog.h index 6d36dd9..85d3da9 100644 --- a/tools/libxc/xentoollog.h +++ b/tools/libxc/xentoollog.h @@ -65,9 +65,11 @@ struct xentoollog_logger { /*---------- facilities for consuming log messages ----------*/ -#define XTL_STDIOSTREAM_SHOW_PID 01u -#define XTL_STDIOSTREAM_SHOW_DATE 02u -#define XTL_STDIOSTREAM_HIDE_PROGRESS 04u +#define XTL_STDIOSTREAM_SHOW_PID 001u +#define XTL_STDIOSTREAM_SHOW_DATE 002u +#define XTL_STDIOSTREAM_HIDE_PROGRESS 004u +#define XTL_STDIOSTREAM_PROGRESS_USE_CR 010u /* default is to */ +#define XTL_STDIOSTREAM_PROGRESS_NO_CR 020u /* use \r to ttys */ typedef struct xentoollog_logger_stdiostream xentoollog_logger_stdiostream; diff --git a/tools/libxc/xtl_logger_stdio.c b/tools/libxc/xtl_logger_stdio.c index aa5501f..47ee257 100644 --- a/tools/libxc/xtl_logger_stdio.c +++ b/tools/libxc/xtl_logger_stdio.c @@ -28,6 +28,7 @@ #include #include #include +#include struct xentoollog_logger_stdiostream { xentoollog_logger vtable; @@ -35,7 +36,7 @@ struct xentoollog_logger_stdiostream { xentoollog_level min_level; unsigned flags; int progress_erase_len, progress_last_percent; - int tty; + bool progress_use_cr; }; static void progress_erase(xentoollog_logger_stdiostream *lg) { @@ -119,7 +120,7 @@ static void stdiostream_progress(struct xentoollog_logger *logger_in, lg->progress_last_percent = percent; - if (!lg->tty) { + if (!lg->progress_use_cr) { stdiostream_message(logger_in, this_level, context, "%s: %lu/%lu %3d%%", doing_what, done, total, percent); @@ -167,7 +168,18 @@ xentoollog_logger_stdiostream *xtl_createlogger_stdiostream newlogger.f = f; newlogger.min_level = min_level; newlogger.flags = flags; - newlogger.tty = isatty(fileno(newlogger.f)) > 0; + + switch (flags & (XTL_STDIOSTREAM_PROGRESS_USE_CR | + XTL_STDIOSTREAM_PROGRESS_NO_CR)) { + case XTL_STDIOSTREAM_PROGRESS_USE_CR: newlogger.progress_use_cr = 1; break; + case XTL_STDIOSTREAM_PROGRESS_NO_CR: newlogger.progress_use_cr = 0; break; + case 0: + newlogger.progress_use_cr = isatty(fileno(newlogger.f)) > 0; + break; + default: + errno = EINVAL; + return 0; + } if (newlogger.flags & XTL_STDIOSTREAM_SHOW_DATE) tzset(); -- 1.7.10.4