xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Ian Jackson <ian.jackson@eu.citrix.com>
To: xen-devel@lists.xensource.com
Cc: Ian Jackson <Ian.Jackson@eu.citrix.com>
Subject: [PATCH 1/3] xl: Break out flush_stream
Date: Fri, 3 Jul 2015 12:48:43 +0100	[thread overview]
Message-ID: <1435924125-20635-1-git-send-email-ian.jackson@eu.citrix.com> (raw)
In-Reply-To: <21910.29314.679455.196969@mariner.uk.xensource.com>

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 <Ian.Jackson@eu.citrix.com>
---
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

  reply	other threads:[~2015-07-03 11:48 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-26 14:29 [PATCH] xl: Change output from xl -N create to be more useful Ian Jackson
2015-06-26 14:36 ` Ian Jackson
2015-06-26 15:10 ` Wei Liu
2015-06-26 15:30   ` Ian Jackson
2015-06-30 11:22     ` Ian Campbell
2015-07-03 11:10 ` Ian Jackson
2015-07-03 11:25 ` Ian Campbell
2015-07-03 11:31   ` Ian Jackson
2015-07-03 11:48     ` Ian Jackson [this message]
2015-07-03 11:48       ` [PATCH 2/3] " Ian Jackson
2015-07-03 13:44         ` [PATCH 2/3] xl: Change output from xl -N create to be more useful [and 1 more messages] Ian Jackson
2015-07-03 11:48       ` [PATCH 3/3] xl: xl -N create -d sends json output to stdout, not stderr Ian Jackson
2015-07-03 12:06       ` [PATCH 1/3] xl: Break out flush_stream Ian Campbell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1435924125-20635-1-git-send-email-ian.jackson@eu.citrix.com \
    --to=ian.jackson@eu.citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).