From: Olaf Hering Subject: [PATCH v2] tools/xc: update tty detection in stdiostream_progress Date: Wed, 27 Feb 2013 15:16:36 +0100 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: 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 Cc: Ian Jackson List-Id: xen-devel@lists.xenproject.org # HG changeset patch # User Olaf Hering # Date 1361974429 -3600 # Node ID c438c98e13163cdb3106917469e3b86226f96168 # Parent dc086ced6b0c7ecf21e56155f42fb16dabe39097 tools/xc: update tty detection in stdiostream_progress As suggested by IanJ: Check isatty only once to preserve the errno of ->progress users, and to reduce the noice in strace output. v2: - fix compile error - rename ->isatty to ->tty Signed-off-by: Olaf Hering diff -r dc086ced6b0c -r c438c98e1316 tools/libxc/xtl_logger_stdio.c --- a/tools/libxc/xtl_logger_stdio.c +++ b/tools/libxc/xtl_logger_stdio.c @@ -35,6 +35,7 @@ struct xentoollog_logger_stdiostream { xentoollog_level min_level; unsigned flags; int progress_erase_len, progress_last_percent; + int tty; }; static void progress_erase(xentoollog_logger_stdiostream *lg) { @@ -118,7 +119,7 @@ static void stdiostream_progress(struct lg->progress_last_percent = percent; - if (isatty(fileno(lg->f)) <= 0) { + if (!lg->tty) { stdiostream_message(logger_in, this_level, context, "%s: %lu/%lu %3d%%", doing_what, done, total, percent); @@ -166,6 +167,7 @@ xentoollog_logger_stdiostream *xtl_creat newlogger.f = f; newlogger.min_level = min_level; newlogger.flags = flags; + newlogger.tty = isatty(fileno(newlogger.f)) > 0; if (newlogger.flags & XTL_STDIOSTREAM_SHOW_DATE) tzset();