From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Jackson Subject: [PATCH 1/3] xl: Break out flush_stream Date: Fri, 3 Jul 2015 12:48:43 +0100 Message-ID: <1435924125-20635-1-git-send-email-ian.jackson@eu.citrix.com> References: <21910.29314.679455.196969@mariner.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <21910.29314.679455.196969@mariner.uk.xensource.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: Ian Jackson List-Id: xen-devel@lists.xenproject.org We are going to want to reuse this. Adjust the code slightly to detect right away call sites that pass something other than stdout or stderr. No resulting functional change. Signed-off-by: Ian Jackson --- v2: New patch in this version of the mini-series --- tools/libxl/xl_cmdimpl.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index c858068..ee55786 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -389,6 +389,20 @@ static yajl_gen_status printf_info_one_json(yajl_gen hand, int domid, out: return s; } + +static void flush_stream(FILE *fh) +{ + const char *fh_name = + fh == stdout ? "stdout" : + fh == stderr ? "stderr" : + (abort(), (const char*)0); + + if (ferror(fh) || fflush(fh)) { + perror(fh_name); + exit(-1); + } +} + static void printf_info(enum output_format output_format, int domid, libxl_domain_config *d_config, FILE *fh) @@ -424,13 +438,7 @@ out: fprintf(stderr, "unable to format domain config as JSON (YAJL:%d)\n", s); - if (ferror(fh) || fflush(fh)) { - if (fh == stdout) - perror("stdout"); - else - perror("stderr"); - exit(-1); - } + flush_stream(fh); } static int do_daemonize(char *name) -- 1.7.10.4