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>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
v2: New patch in this version of the mini-series
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)
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)