From: Ian Jackson Date: Fri, 3 Jul 2015 11:36:20 +0000 (+0100) Subject: xl: Break out flush_stream X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~2946^2~2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=58072f13da55ee59a1543783cc9c9015fcb9be70;p=xen.git xl: Break out flush_stream 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 Acked-by: Ian Campbell --- v2: New patch in this version of the mini-series --- diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index c858068b39..ee5578684c 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)